Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Not able to print the message in the T-sql code Expand / Collapse
Author
Message
Posted Thursday, November 19, 2009 12:06 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, August 29, 2014 4:54 PM
Points: 310, Visits: 656
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?
Post #821378
Posted Thursday, November 19, 2009 1:45 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 8:16 AM
Points: 2,663, Visits: 5,814
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



Post #821394
Posted Thursday, November 19, 2009 2:12 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, March 4, 2014 10:03 AM
Points: 1,106, Visits: 1,334
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
Post #821403
Posted Thursday, November 19, 2009 7:49 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 22, 2014 4:56 AM
Points: 1,093, Visits: 2,617
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
Post #821622
Posted Sunday, November 22, 2009 11:54 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, August 29, 2014 4:54 PM
Points: 310, Visits: 656
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
Post #823106
Posted Tuesday, August 13, 2013 10:16 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 13, 2013 10:10 AM
Points: 3, Visits: 16
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
Post #1483855
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse