Bunch's Blog

One day I'll have a catchy subtitle, one day
posts - 87 , comments - 120 , trackbacks - 0

PRINT Ints in TSQL

To print multiple int variables on one line you need to CAST them first. Otherwise the PRINT command will add them up (at least it does for me anyways using SQL 2008). In the example I needed to have two ID variables print out while I was working on a sproc so I could see if I was getting the correct IDs before adding in my update code.

This did not work, it adds the two variables together:

PRINT @FirstID + ‘ – ‘ + @NextID

This does work, it prints each variable with the dash in-between:

PRINT CAST(@FirstID AS Varchar(20)) + ‘ – ‘ + CAST(@NextID AS Varchar(20))

Technorati Tags:

Print | posted on Thursday, October 20, 2011 10:48 AM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 
 

Powered by: