Script:<\/em>
\n[sql]
\nCREATE TABLE TestTable(Value VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS)
\nGO
\nCREATE TABLE ReferTable(Value VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS)
\nGO<\/p>\nINSERT INTO TestTable(Value)
\nSELECT ‘lowercase’
\nUNION ALL
\nSELECT ‘LowerCase’
\nUNION ALL
\nSELECT ‘LOWERCASE’
\nGO<\/p>\n
INSERT INTO ReferTable(Value)
\nSELECT ‘lowercase’
\nGO<\/p>\n
–This query gives all three rows
\n–No need of lower
\nSELECT * FROM TestTable T JOIN ReferTable R
\nON T.Value = R.Value<\/p>\n
———————————————————
\nCREATE TABLE TestTable1(Value VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CS_AS)
\nGO
\nCREATE TABLE ReferTable1(Value VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CS_AS)
\nGO<\/p>\n
INSERT INTO TestTable1(Value)
\nSELECT ‘lowercase’
\nUNION ALL
\nSELECT ‘LowerCase’
\nUNION ALL
\nSELECT ‘LOWERCASE’
\nGO<\/p>\n
INSERT INTO ReferTable1(Value)
\nSELECT ‘lowercase’
\nGO<\/p>\n
–This query gives only one row
\nSELECT * FROM TestTable1 T JOIN ReferTable1 R
\nON T.Value = R.Value
\n[\/sql]<\/p>\n
In such scenarios as discussed above, we have to specify LOWER along with the column names to compare UpperCase with Lower Case.<\/p>\n
[sql]
\n–Needs Lower to give all the tree rows
\nSELECT * FROM TestTable1 T JOIN ReferTable1 R
\nON LOWER(T.Value) = LOWER(R.Value)
\n[\/sql]<\/p>\n
Observations:<\/strong>
\nLOWER Can be ignored if the database and all the table columns that are specified in the query are in CASE INSENSITIVE Collation.<\/p>\nAlternatives:<\/strong>
\nWe can specify the CASE INSENSITIVE Collation name with the column name to compare the column using Case insensitive Collation.
\n[sql]
\n–Alternative to LOWER\/UPPER
\n–Using CASE InSensitive Collation names in the query
\nSELECT * FROM TestTable1 T JOIN ReferTable1 R
\nON T.Value COLLATE SQL_Latin1_General_CP1_CI_AS =
\n R.Value COLLATE SQL_Latin1_General_CP1_CI_AS
\n[\/sql]<\/p>\nClean Up:<\/em>
\n[sql]
\nUSE master
\nGO<\/p>\nDROP DATABASE testLower
\n[\/sql]<\/p>\n","protected":false},"excerpt":{"rendered":"
In SQL Server LOWER Can be used to convert uppercase\/mixedcase string to lower case string. More about LOWER can be found here Similarly, UPPER Can be used to convert lowercase\/mixedcase string to upper case string. More about UPPER can be found here Example: [sql] DECLARE @String VARCHAR(10) SET @String = ‘ABcDeFGH’ SELECT @String STRING,LOWER(@String) LowerCaseSrting…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2167,41],"tags":[],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-collations","category-sql-server-basics"],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}