i get an error when creating a variable and specifing the collation in sql server 2005

强颜欢笑 提交于 2019-12-16 18:04:22

问题


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:


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.



来源:https://stackoverflow.com/questions/3919780/i-get-an-error-when-creating-a-variable-and-specifing-the-collation-in-sql-serve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!