SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Not able to print the message in the T-sql code


Not able to print the message in the T-sql code

Author
Message
luckysql.kinda
luckysql.kinda
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1578 Visits: 659
Hi all,

when I run a big code then I use following print command as well
PRINT 'BEFORE NEW SRNO STARTS @MobileCode= '+@MobileCode+' @MobileCodeNew ='+@MobileCodeNew+'@MobileCodeForN ='+@MobileCodeForN+'@RCOOC ='+@RCOOC+'@MobileCodeForN ='+@MobileCodeForN

This doesn't work eventhough the sqlos reads this line... I verified from the debug as well. Is there any setting that could have made this off?
Mike John
Mike John
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3318 Visits: 5983
My bet would be one (or more) of the variables is NULL, and any operation that concatenates NULL with another value will return a null, hence the entire expression is null which in a print statement looks a lot like a blank line!

(Assuming default settings for null behaviour are in use)

Mike John



Schadenfreude-Mei
Schadenfreude-Mei
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3569 Visits: 1336
luckysql.kinda (11/19/2009)

This doesn't work eventhough the sqlos reads this line... I verified from the debug as well. Is there any setting that could have made this off?


What is the output (ie what 'are' you getting)? At the least you should see:

BEFORE NEW SRNO STARTS @MobileCode =@MobileCodeNew =@MobileCodeForN =@RCOOC =@MobileCodeForN =


If you get the above (or something like it) your PRINT is working but something in your variables or the way their values are calculated is not.

Adam Zacks

-------------------------------------------

Be Nice, Or Leave
Richard M.
Richard M.
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2106 Visits: 2686
If the output of the PRINT is just a blank line, then one or more of the variables contains a NULL, as Mike stated above.

You probably would have to use a somewhat more "complicated" way to do the print:

PRINT 'BEFORE NEW SRNO STARTS @MobileCode= '+COALESCE(@MobileCode,'')+' @MobileCodeNew ='+COALESCE(@MobileCodeNew,'')+'@MobileCodeForN ='+COALESCE(@MobileCodeForN,'')+'@RCOOC ='+COALESCE(@RCOOC,'')+'@MobileCodeForN ='+COALESCE(@MobileCodeForN,'')

That way you can at least identify which one is the culprit. This will also give you an output as Adam posted above.

_______________________________________________________________________
For better assistance in answering your questions, click here
luckysql.kinda
luckysql.kinda
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1578 Visits: 659
Thanks Richard. This seems that some of the variable would have corrupted in mid and got NULL. Now this works.

Thanks again to all.
-Lk
jackbhanded
jackbhanded
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 18
To avoid this problem in any complicated stored procedures, initialize the variable to empty before using them in any string manipulation.

e.g.

Declare @MobileCode as varchar(50), @MobileCodeNew as varchar(50), @MobileCodeForN as varchar(50), @RCOOC as varchar(50)

select @MobileCode = ''
select @MobileCodeNew = ''
select @MobileCodeForN = ''
select @RCOOC = ''

-- do what you got to do!
-- do what you got to do!

PRINT 'BEFORE NEW SRNO STARTS @MobileCode= '+@MobileCode+' @MobileCodeNew ='+@MobileCodeNew+'@MobileCodeForN ='+@MobileCodeForN+'@RCOOC ='+@RCOOC+'@MobileCodeForN ='+@MobileCodeForN
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search