Farhad-Taran
Farhad-Taran

Reputation: 6540

formatting sql server PRINT messages?

I have the following Print statement which print some details but it is not tabbed properly and looks awful. is there any way i could print them in tabbed format so they all meet at the same place in the end of the line.

Print'ByLineID: '+ Convert (varchar,@bylineID,1 )+' , '+ Convert(varchar,@Count,1)+ ' matching records found, '+ Convert(varchar,@@rowcount,1)+' updated.'  

End result:

ByLineID: 119952    , 168 matching records found, 0 updated.
ByLineID: 93979 , 56 matching records found, 0 updated.
ByLineID: 266021    , 45 matching records found, 0 updated.
ByLineID: 105976    , 44 matching records found, 0 updated.
ByLineID: 97525 , 40 matching records found, 0 updated.
ByLineID: 94138 , 39 matching records found, 0 updated.
ByLineID: 88967 , 37 matching records found, 0 updated.

Upvotes: 1

Views: 6172

Answers (2)

EricZ
EricZ

Reputation: 6205

First, CONVERT VARCHAR without length is bad idea, you should try Convert (varchar(10), @bylineID).

Also, if those info are important for you, you may consider create a log table, or at least temp log table to store those information, and select from log table to get better output.

CREATE TABLE #logmsg
 ( id INT Identity (1,1)
 , ByLineID VARCHAR(10)
 , RecordMatch INT
 , RecordUpdted INT
 , CreateDate DateTime DEFAULT(GETDATE())) 

Upvotes: 0

gbn
gbn

Reputation: 432662

Print
      'ByLineID: '+ 
      Convert (varchar,@bylineID,1 ) + char(9) + ' , ' +
      Convert(varchar,@Count,1)  + char(9) +
      ' matching records found, ' +
      Convert(varchar,@@rowcount,1) + char(9) +' updated.'

Add some tab characters?

Upvotes: 5

Related Questions