What is the difference between Empty-> '' string between Space-> ' ' in Sql Server ?

declare @Spacevalue nvarchar(10)
declare @Spacevalue2 nvarchar(10)

set @Spacevalue = ''
set @Spacevalue2 = ' '

if @Spacevalue like @Spacevalue2
print '@Spacevalue Like @Spacevalue2'
else
print '@Spacevalue Not Like @Spacevalue2'

if @Spacevalue2 like @Spacevalue
print '@Spacevalue2 Like @Spacevalue'
else
print '@Spacevalue2 Not Like @Spacevalue'

-- @Spacevalue Not Like @Spacevalue2
-- @Spacevalue2 Not Like @Spacevalue


print(DATALENGTH(' ')) --1
print(LEN(' '))        --0


if '' = ' '
print 'equal'
else
print 'not equal'
-- equal

if '' LIKE ' '
print 'equal'
else
print 'not equal'
-- not equal

IF ASCII('') = 32 PRINT 'equal' ELSE PRINT 'not equal'
-- not equal


About Author: author 4 + years of Information Technology experience in understanding and analyzing the software and hardware engineering requirements, onsite and offshore management of product development. Expert work on design and development for windows,web,mobile Expert knowledge of C#,ADO.NET, ASP.Net MVC, ENTITY FRAMEWORK, LINQ,COLLECTIONS, JAVASCRIPT,AngularJs 1.0,Angular2, Jquery,Jquery-Ajax, SQL SERVER, XAML,Windows phone 8.1 Good knowledge of WCF-Restful services,WCF, WEB API-Services ,Web- Services,MIcrosoft-Azure,JUICE UI,HTML,CSS,AJAX Read More...

Join him on Google+ | Facebook | Linkedin

No comments