Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 CHAR(9) and CHAR(13) in stored procedure

Author  Topic 

danyeung
Posting Yak Master

102 Posts

Posted - 2006-03-07 : 13:04:14
1) What do CHAR(9) and CHAR(13) do in the following statement in stored procedure? Why are they needed?

SET @@nvchrTSQL = @@nvchrTSQL + CHAR(9) + 'tblReferralRequest.nvchrLastName as [Last Name], ' + CHAR(13)

2) Does the following statement execute the SQL? Where is sp_executesql?

EXECUTE sp_executesql @@nvchrTSQL

Thanks.
DanYeung

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-03-07 : 13:14:14
Lookup CHAR function in BOL. CHAR(9) produces a tab and CHAR(13) produces a carriage return. They are being used to format the SQL string that is then executed by the system stored procedure sp_executesql (there is also a full description of this in BOL).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-03-07 : 13:19:49
I sometimes format my dynamic string just like the code that you posted. It is very helpful for me when debugging as it makes it easier to read when I PRINT @@nvchrTSQL in Query Analyzer. Otherwise, you'll have this very long T-SQL string. I don't always do it. Just when I know that the dynamic query is going to be long and I'm going to need to debug.

Tara Kizer
aka tduggan
Go to Top of Page

danyeung
Posting Yak Master

102 Posts

Posted - 2006-03-07 : 14:12:47
Thanks.

Thanks.
DanYeung
Go to Top of Page
   

- Advertisement -