Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
In a sql server 2008 r2 database column that is defined as varchar, how do you check to see if the field contains all spaces regardless of the length the field is?
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-10-06 : 18:39:31
A few different ways you can do this, see in red below:
DECLARE @x VARCHAR(32) = ' ';SELECT CASE WHEN LTRIM(@x) = '' THEN 'All spaces' ELSE 'Not all spaces' END , CASE WHEN LEN(@x) = 0 THEN 'All spaces' ELSE 'Not all spaces' END , CASE WHEN REPLACE(@x,' ','') = '' THEN 'All spaces' ELSE 'Not all spaces' END , CASE WHEN NULLIF(@x,'') IS NULL THEN 'All spaces' ELSE 'Not all spaces' END ;
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-10-07 : 13:08:34
one more way
DECLARE @x VARCHAR(32) = ' ';SELECT CASE WHEN @x > '' THEN 'Not all spaces' ELSE 'All spaces' END
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/