Cast collation of nvarchar variables in t-sql

Sandor Davidhazi picture Sandor Davidhazi · Oct 27, 2009 · Viewed 57k times · Source

I need to change the collation of an nvarchar variable. By documentation:

(...) 3. The COLLATE clause can be specified at several levels. These include the following:

Casting the collation of an expression. You can use the COLLATE clause to apply a character expression to a certain collation. Character literals and variables are assigned the default collation of the current database. Column references are assigned the definition collation of the column. For the collation of an expression, see Collation Precedence (Transact-SQL).

However I can't figure out the correct syntax for the usage of CAST(), CONVERT() or variable declaration with DECLARE for this purpose.

Answer

Lukasz Lysik picture Lukasz Lysik · Oct 27, 2009
SELECT CAST('abc' AS varchar(5)) COLLATE French_CS_AS