SQL statement to validate an empty string - T-SQL

I am trying to write a sentence WHEREwhere a specific string variable is not null or empty. The problem I am facing is that some non-empty lines are literal N''. For instance:

declare @str nvarchar(max) = N'㴆';
select case when @str = N'' then 1 else 0 end;

Profitability 1. From what I can compile on Wikipedia , this particular Unicode character is an icon for immersing something that is not semantically equal to an empty string. In addition, the string length is 1, at least in T-SQL.

Is there a better (exact) way to check a T-SQL variable for an empty string?

+4
source share
1 answer

, https://bbzippo.wordpress.com/2013/09/10/sql-server-collations-and-string-comparison-issues/

,

, (SQL_Latin1_General_CP1_CI_AS) SQL Server Unicode, (4- ).

, . :

select case when N'㴆' COLLATE Latin1_General_100_CI_AS_KS_WS = N'' then 1 else 0 end;

0. . .

, .

declare @str1 nvarchar(max) =N'㴆';
select case when len(@str1) = 0 then 1 else 0 end;

0, .

0, null.

EDIT:

devio Erland Sommarskog https://groups.google.com/forum/#!topic/microsoft.public.sqlserver.server/X8UhQaP9KF0

, Latin1_General_CP1_CI_AS . , is .

Latin1_General_100_CI_AS .

+6

Source: https://habr.com/ru/post/1670248/


All Articles