Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below query work well on sql server 2008 R2

create FUNCTION [dbo].[sortingfunction]
(
@column varchar(max)
)
RETURNS varchar(max)
AS
BEGIN
Declare @num varchar(50)
Declare @space varchar(50)
Declare @index int = 1
set @num = LEFT(SUBSTRING(@column, PATINDEX('%[0-9.-]%', @column), 8000), PATINDEX('%[^0-9.-]%', SUBSTRING(@column, PATINDEX('%[0-9.-]%', @column), 8000) + 'X')-1)
set @space = replicate(' ', 20 - len(@num))
return replace(@column, @num, @space + @num)
END

----------------------------------------------------------------------
select from sampletable order by dbo.sortingfunction(key)


while on sql server 2005 it saying that

Msg 139, Level 15, State 1, Procedure sortingfunction, Line 0
Cannot assign a default value to a local variable.


please help
Posted
Updated 7-Dec-13 23:17pm
v2

1 solution

Change this line:
Quote:
Declare @index int = 1

To this:
Quote:
Declare @index int
Set @index = 1

The initialisation syntax was added after SQL 2005.
 
Share this answer
 
Comments
patil.nitin8358 8-Dec-13 5:28am    
Hello NeverJustHere,

Thanks for the solution .

It works for me.

Good

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900