Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2004
    Posts
    74

    Unanswered: Why it doesn't print result ?

    Hi All,
    in below query, i wonder why if i uncomment print statement , then only result allow to print out ?

    for testing purpose, i have set the same @id , but it doesn't print any if i have remark it



    Code:
    BEGIN
    SELECT		TOP 1 
    			@a = rep_nt_logon  				
    			,@b = [start_date]
    FROM		temp temp
    WHERE		temp.role_id =123
    AND			temp.primary_owner = 1
    AND			temp.id = @id
    ORDER BY	temp.primary_owner, CONVERT(datetime, [start_date] ) DESC
    END
    
    IF			@a = ''
    --print 'test'
    BEGIN
    SELECT		TOP 1 
    			@a = temp.rep_nt_logon
    			,@b = temp.[start_date]
    			FROM		temp temp
    			WHERE		temp.role_id =123
    			AND			(temp.primary_owner IS NULL OR temp.primary_owner=0)
    			AND			temp.id = @id
    			ORDER BY	CONVERT(datetime, temp.start_date ) DESC
    				
    END
    
    PRINT 'partyid : ' + cast(@id as nvarchar(20)) + '  out USER : ' + (@a) + '  out date : ' + (@b)

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Is @a NULL?
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2004
    Posts
    74
    Thanks George,

    i believe it is not NULL, cause if i uncomment print 'Test', then it will appear the result ...what will be the next glue in your best experience ?

    if i try to print @a, it doesn't show any value

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    PRINT @a
    PRINT Coalesce(@a, 'A is NULL')
    Any result?
    George
    Home | Blog

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by alvincks
    i believe it is not NULL, cause if i uncomment print 'Test', then it will appear the result ...what will be the next glue in your best experience ?
    But after seeing that it is '', you then set it again. Worrabout @b too?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Mar 2004
    Posts
    74
    yup, @B can be NULL

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by alvincks
    yup, @B can be NULL
    ' out date : ' + NULL
    will become NULL.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Code:
    IF			@a = ''
    --print 'test'
    BEGIN
    SELECT
    Why is the print statement not inside the BEGIN/END block? if it is uncommented, the IF clause (when true) will execute the print statement AND the select statement.

  9. #9
    Join Date
    Mar 2004
    Posts
    74
    Thanks All , i found it , it really cause by NULL value

    after i put the condition as

    if @a = '' OR @a IS NULL

    it work now ......thanks everyone again who participate and enlighten me , appreciated your help !

    just one last question , do i have chance to combine the above 2 checking criterias into one ?

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    If NullIf(@a, '') IS NULL
    OR
    Code:
    IF Coalesce(@a, '') = ''
    George
    Home | Blog

  11. #11
    Join Date
    Mar 2004
    Posts
    74
    Thanks Georg

  12. #12
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    do a '*' + @a + '*' to see if anything in between.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •