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)
 Insert Char(13) into SQL table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-04-11 : 08:17:16
Jimmy writes "I have a cursor that loops through rows in a table, appending the row text plus a CHAR(13) to a NVARCHAR variable. Example: @strDOCTEXT = @strDOCTEXT + @OBSVALUE + CHAR(13)

All of the source and destination fields and variables are NVARCHAR datatypes.

After the @strDOCTEXT has been properly populated, I insert this variable into a field in another table with a NVARCHAR datatype.

However, SQL does not insert the CHAR(13) into the field in the other table. If I use the SQL Print statement within the cursor to display to variable in SQL Query Analyzer, the formatting is perfect.

Does SQL only support appending ASCII characters for display purposes only?

Do you know another way I can have SQL append the CHAR(13) to the variable and insert into another table, keeping the proper formatting?

Thanks,
Jimmy"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-04-11 : 08:30:39
1. Piece of good advice.....Stay away from CURSORS. Search here for why (hint add POOR PERFORMANCE to the search terms). What you are trying ot be done SHOULD be do-able using a SET-BASED technique...(again search here for info)
2. IF you do "SELECT * from anothertable" what do you see in QA? Is the data formatted across 2 lines? You won't be able to "see" char(13) in the data...you can only see the effect of it.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-04-11 : 09:01:19
Why store the CHAR(13) with the data? if it is a constant, just add it to the end when you query the table, or have the presentation layer add it. I would have to say that it's not a good idea to force the storage of unncessary formatting controls in your data, espcially when they are constants. And if they are NOT constant for all rows, but important to store, then just add a bit (boolean) column called "CR" or something like that that is 1 or 0 depending on whether or not a CHAR(13) should be appended to the end of the text.

- Jeff
Go to Top of Page
   

- Advertisement -