Monday, September 6, 2010

Formatting SQL output string

Step 1: Putting a record into a sentence.
You can build a sentence off a row using SELECT. For example,

SELECT [Who] + ' is going to do ' + [Item] + 'on '+ CONVERT(VARCHAR, [due], 105) + '.'
        FROM [Actions]

Step 2: Format the sentence.
When you want to putting line break or even a tab in your output, you may need CHAR function in SQL.
Tabchar(9)
Line feedchar(10)
Carriage returnchar(13)

Details see http://msdn.microsoft.com/en-us/library/ms187323.aspx

Step 3: Form an essay with multiple records.
You may need to use CURSOR to iterate the rows from the result table.
 

No comments:

Post a Comment