views:

38

answers:

1

when i tried this:

DECLARE @var nvarchar(500) collate Arabic_BIN

i got that:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'collate'.

that is the full code, it works, i do not know how but the person who give it to me have used it successfully

CREATE FUNCTION fn_RemoveTashkeel (@InputString nvarchar(2300) )

RETURNS nvarchar(2300)

AS
BEGIN
   DECLARE @OutputString nvarchar(2300) COLLATE Arabic_BIN 
   DECLARE @TashkeelChr char(8) COLLATE Arabic_BIN 
   DECLARE @feed int
   SET @OutputString=@InputString
   SET @TashkeelChr='ًٌٍَُِّْْْْْ'
   SET @feed=1
 WHILE @feed<=LEN(@TashkeelChr)
   BEGIN
    SET @OutputString=REPLACE(@OutputString,SUBSTRING(@TashkeelChr,@feed,1),'')
    SET @feed=@feed+1
   END
   RETURN(@OutputString)
END
+1  A: 

You don't set collation in a variable declaration. Per the MSDN documentation:

Collate:

Is a clause that can be applied to a database definition or a column definition to define the collation, or to a character string expression to apply a collation cast.

In other words, you set collation at the database level, as part of a table's column definition, or in SELECT statements.

See the MSDN documentation for more information.

LittleBobbyTables
i have modified the question please read it again
mostafa
@mostafa - My answer still stands -- you can't use COLLATE for variables. You're saying this function is currently in production as you have it, and it works, but you can't add `@var` to it?
LittleBobbyTables
i just want the full code to work with me as with my friend, and all the errors that i have got refer to collate keyword so i thought i can just put similar line of code as an example of my question, but if you want the full code yes it is that function
mostafa
@mostafa: I'm testing on SS2005--the function posted will not compile until the COLLATE declarations on the two string based data types have been removed. As Bobby quoted the documentation, that's not how you use the COLLATE keyword in TSQL. Have you tested the version that will compile to confirm there is still a collation issue? Because I could see the need to address the collation of the variable reference in the `SET` statement, but not in the `DECLARE`. Sorry, but language on the internet is still primary English--I couldn't actually test because I don't know Arabic.
OMG Ponies
i have tried to declare the variables with English based collation anyway but it did not work also. anyway thank you.
mostafa
@OMG - thanks for the double-check!
LittleBobbyTables