Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL change field Collation in a select

Tags:

sql-server

i'm trying to do the following select:

select * from urlpath where substring(urlpathpath, 3, len(urlpathpath))
not in (select accessuserpassword from accessuser where accessuserparentid = 257)

I get the error:

Cannot resolve the collation conflict between 
"SQL_Latin1_General_CP1_CI_AI" and 
"SQL_Latin1_General_CP1_CI_AS" in the equal to operation.

Does anyone know how i can cast as a collation, or something that permits me to match this condition?

Thanx

like image 919
André Alçada Padez Avatar asked Dec 19 '10 17:12

André Alçada Padez


People also ask

How do I change collation in select?

You can change the collation of any new objects that are created in a user database by using the COLLATE clause of the ALTER DATABASE statement. This statement does not change the collation of the columns in any existing user-defined tables. These can be changed by using the COLLATE clause of ALTER TABLE.

How do I make columns case sensitive in SQL Server?

SQL Server is, by default case insensitive; however, it is possible to create a case sensitive SQL Server database and even to make specific table columns case sensitive. The way to determine a database or database object is by checking its “COLLATION” property and look for “CI” or “CS” in the result.


1 Answers

You can even do the collate on the query to create a new table with that query, for example:

SELECT 
    * 
INTO 
    #TempTable  
FROM 
    View_total
WHERE 
        YEAR(ValidFrom) <= 2007 
    AND YEAR(ValidTo)>= 2007 
    AND Id_Product = '001' 
    AND ProductLine COLLATE DATABASE_DEFAULT IN (SELECT Product FROM #TempAUX) 

COLLATE DATABASE_DEFAULT causes the COLLATE clause inherits the collation of the current database, eliminating the difference between the two

like image 105
David Lozano Avatar answered Sep 19 '22 16:09

David Lozano