Code
IF ' ' = ' '
PRINT '['' '' = '' ''] = true'
--doesn't work
IF NULL = '' OR NULL <> ''
PRINT 'NULL = '''' OR NULL <> '''''
IF ISNULL(NULL,'') = ''
PRINT '[ISNULL(NULL,'''') = '''' ] is true'
IF ISNULL(' ','null') = ''
PRINT '[ISNULL('' '',''null'') = NULL] is true'
PRINT dbo.FN_DAC_Compare(null,null)--1
PRINT dbo.FN_DAC_Compare(null,'')--1
PRINT dbo.FN_DAC_Compare('',null)--1
PRINT dbo.FN_DAC_Compare(null,' ')--0
PRINT dbo.FN_DAC_Compare(' ',null)--0
PRINT dbo.FN_DAC_Compare(null,'1')--0
PRINT dbo.FN_DAC_Compare('1',null)--0
PRINT dbo.FN_DAC_Compare('1','1')--1
PRINT dbo.FN_DAC_Compare('1','2')--0
PRINT dbo.FN_DAC_Compare('1 ',' 1')--0
PRINT dbo.FN_DAC_Compare('','')--1
PRINT dbo.FN_DAC_Compare(' ','')--0
PRINT dbo.FN_DAC_Compare('',' ')--0
PRINT dbo.[FN_DAC_IsEmptyOrNull](null)--1
PRINT dbo.[FN_DAC_IsEmptyOrNull]('')--1
PRINT dbo.[FN_DAC_IsEmptyOrNull](' ')--0
PRINT dbo.[FN_DAC_IsEmptyOrNull](' 2 ')--0
PRINT dbo.[FN_DAC_IsEmptyOrNull]('1')--0
CREATE FUNCTION [FN_DAC_IsEmptyOrNull](@input VARCHAR(MAX))
RETURNS BIT
AS
BEGIN
DECLARE @NullString VARCHAR(MAX)
SET @NullString = '@NullString!@#$@NullString!@#$@NullString!@#$!@#$%^!@#$%'
IF ISNULL(@input,@NullString) = @NullString
RETURN 1
IF LEN('#' + @input + '#') = 2
RETURN 1
RETURN 0
END
CREATE FUNCTION [dbo].[FN_DAC_Compare](@input1 VARCHAR(MAX),@input2 VARCHAR(MAX))
RETURNS BIT
AS
BEGIN
IF DBO.FN_DAC_IsEmptyOrNull(@input1) <> DBO.FN_DAC_IsEmptyOrNull(@input2)
RETURN 0
ELSE
BEGIN
IF DBO.FN_DAC_IsEmptyOrNull(@input1) = 1
RETURN 1
ELSE IF '#' + @input1 + '#' = '#' + @input2 + '#'
RETURN 1
END
RETURN 0
END
IF ' ' = ' '
PRINT '['' '' = '' ''] = true'
--doesn't work
IF NULL = '' OR NULL <> ''
PRINT 'NULL = '''' OR NULL <> '''''
IF ISNULL(NULL,'') = ''
PRINT '[ISNULL(NULL,'''') = '''' ] is true'
IF ISNULL(' ','null') = ''
PRINT '[ISNULL('' '',''null'') = NULL] is true'
PRINT dbo.FN_DAC_Compare(null,null)--1
PRINT dbo.FN_DAC_Compare(null,'')--1
PRINT dbo.FN_DAC_Compare('',null)--1
PRINT dbo.FN_DAC_Compare(null,' ')--0
PRINT dbo.FN_DAC_Compare(' ',null)--0
PRINT dbo.FN_DAC_Compare(null,'1')--0
PRINT dbo.FN_DAC_Compare('1',null)--0
PRINT dbo.FN_DAC_Compare('1','1')--1
PRINT dbo.FN_DAC_Compare('1','2')--0
PRINT dbo.FN_DAC_Compare('1 ',' 1')--0
PRINT dbo.FN_DAC_Compare('','')--1
PRINT dbo.FN_DAC_Compare(' ','')--0
PRINT dbo.FN_DAC_Compare('',' ')--0
PRINT dbo.[FN_DAC_IsEmptyOrNull](null)--1
PRINT dbo.[FN_DAC_IsEmptyOrNull]('')--1
PRINT dbo.[FN_DAC_IsEmptyOrNull](' ')--0
PRINT dbo.[FN_DAC_IsEmptyOrNull](' 2 ')--0
PRINT dbo.[FN_DAC_IsEmptyOrNull]('1')--0
CREATE FUNCTION [FN_DAC_IsEmptyOrNull](@input VARCHAR(MAX))
RETURNS BIT
AS
BEGIN
DECLARE @NullString VARCHAR(MAX)
SET @NullString = '@NullString!@#$@NullString!@#$@NullString!@#$!@#$%^!@#$%'
IF ISNULL(@input,@NullString) = @NullString
RETURN 1
IF LEN('#' + @input + '#') = 2
RETURN 1
RETURN 0
END
CREATE FUNCTION [dbo].[FN_DAC_Compare](@input1 VARCHAR(MAX),@input2 VARCHAR(MAX))
RETURNS BIT
AS
BEGIN
IF DBO.FN_DAC_IsEmptyOrNull(@input1) <> DBO.FN_DAC_IsEmptyOrNull(@input2)
RETURN 0
ELSE
BEGIN
IF DBO.FN_DAC_IsEmptyOrNull(@input1) = 1
RETURN 1
ELSE IF '#' + @input1 + '#' = '#' + @input2 + '#'
RETURN 1
END
RETURN 0
END