Collections:
Performing Comparison on Character Strings in SQL Server
How To Perform Comparison on Character Strings in SQL Server Transact-SQL?
✍: FYIcenter.com
Comparison operations on character strings are performed based on the associated collation. Each collation defines rules on how characters are ordered, how character cases and accents are treated, etc. The tutorial exercise below shows you some character string comparison examples using the default collation: SQL_Latin1_General_CP1_CI_AS.
-- Case insensitive DECLARE @x VARCHAR(40), @y VARCHAR(40); SET @x = 'FYIcenter.com'; SET @y = 'fyicenter.COM'; SELECT CASE WHEN @x = @y THEN 'True' ELSE 'False' END; GO True -- digits has less values than letters DECLARE @x VARCHAR(40), @y VARCHAR(40); SET @x = '1234'; SET @y = 'abcd'; SELECT CASE WHEN @x < @y THEN 'True' ELSE 'False' END; GO True -- Trailing spaces are ignored DECLARE @x VARCHAR(40), @y VARCHAR(40); SET @x = 'FYIcenter.com'; SET @y = 'fyicenter.COM '; SELECT CASE WHEN @x = @y THEN 'True' ELSE 'False' END; GO True -- Longer strings have greater values DECLARE @x VARCHAR(40), @y VARCHAR(40); SET @x = 'abcd'; SET @y = 'abcde'; SELECT CASE WHEN @x < @y THEN 'True' ELSE 'False' END; GO True
⇒ BETWEEN - Testing Value in a Range in SQL Server
⇐ Performing Comparison on Date and Time Values in SQL Server
⇑ Boolean Values and Logical Operations in SQL Server Transact-SQL
2017-01-21, 1834🔥, 0💬
Popular Posts:
How To Generate CREATE TABLE Script on an Existing Table in SQL Server? If you want to know how an e...
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...
How To Generate CREATE VIEW Script on an Existing View in SQL Server? If you want to know how an exi...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
How to change the data type of an existing column with "ALTER TABLE" statements in SQL Server? Somet...