I didn't see any similar questions asked on this topic, and I had to research this for something I'm working on right now. Thought I would post the answer for it in case anyone else had the same question.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
char(13)
isCR
. For DOS-/Windows-styleCRLF
linebreaks, you wantchar(13)+char(10)
, like:This is always cool, because when you get exported lists from, say Oracle, then you get records spanning several lines, which in turn can be interesting for, say, cvs files, so beware.
Anyhow, Rob's answer is good, but I would advice to use something else than @, try a few more, like §§@@§§ or something, so it will have a chance for some uniqueness. (But still, remember the length of the
varchar
/nvarchar
field you are inserting into..)I found the answer here: http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/
You just concatenate the string and insert a
CHAR(13)
where you want your line break.Example:
This prints out the following:
Another way to do this is as such:
That is, simply inserting a line break in your query while writing it will add the like break to the database. This works in SQL server Management studio and Query Analyzer. I believe this will also work in C# if you use the @ sign on strings.
Following a Google...
Taking the code from the website:
Looks like it can be done by replacing a placeholder with CHAR(13)
Good question, never done it myself :)
Here's a C# function that prepends a text line to an existing text blob, delimited by CRLFs, and returns a T-SQL expression suitable for
INSERT
orUPDATE
operations. It's got some of our proprietary error handling in it, but once you rip that out, it may be helpful -- I hope so.