どのように改行を挿入し、まさにSQLサーバー VARCHAR/NVARCHAR文字列
-
09-06-2019 - |
質問
こちらでお分かりになった他の同様の質問は、今、私の研究ですので、そのために何か仕事をしています。うと思ったことの回答すると、誰もが同じように質問です。
解決 2
あなただけの連結の文字列を挿入し CHAR(13)
したいライン。
例:
DECLARE @text NVARCHAR(100)
SET @text = 'This is line 1.' + CHAR(13) + 'This is line 2.'
SELECT @text
このプリントアウトしたりすることに
これはライン1.
このライン2.
他のヒント
char(13)
は CR
.DOS-/フロントのスタッフは英語スタイル CRLF
linebreaksたい char(13)+char(10)
, のように:
'This is line 1.' + CHAR(13)+CHAR(10) + 'This is line 2.'
別の言い方をこすると:
INSERT CRLF SELECT 'fox
jumped'
それは、差し込むだけで、ラインの休憩の検索がで書くことによって追加しているデータベースです。この動作はSQLサーバーのエリアマネジメントとクエリの測定を行いました。このままでも仕事でもクライアントまで、フルのC#でご利用の場合は@に看板の文字列です。
string str = @"INSERT CRLF SELECT 'fox
jumped'"
これにSSMSでどのよう改行は、SQL自体の値に置き換えられるスパンライン:
PRINT 'Line 1
Line 2
Line 3'
PRINT ''
PRINT 'How long is a blank line feed?'
PRINT LEN('
')
PRINT ''
PRINT 'What are the ASCII values?'
PRINT ASCII(SUBSTRING('
',1,1))
PRINT ASCII(SUBSTRING('
',2,1))
結果:
1
ライン2
線3
いものの、空行の飼料?
2
そのASCII値?
13
10
やしている場合はご指定の文字列に一線をほぼ!) きを採用 REPLACE()
このような(オプション使用 CHAR(13)+CHAR(10)
として交換):
PRINT REPLACE('Line 1`Line 2`Line 3','`','
')
以下のa Google...
のコードからウェブサイト:
CREATE TABLE CRLF
(
col1 VARCHAR(1000)
)
INSERT CRLF SELECT 'The quick brown@'
INSERT CRLF SELECT 'fox @jumped'
INSERT CRLF SELECT '@over the '
INSERT CRLF SELECT 'log@'
SELECT col1 FROM CRLF
Returns:
col1
-----------------
The quick brown@
fox @jumped
@over the
log@
(4 row(s) affected)
UPDATE CRLF
SET col1 = REPLACE(col1, '@', CHAR(13))
なっているように見えますがきに置き換えたもので、プレースホルダーとの CHAR(13)
良い質問でんでん:)
思ったことに懸念cr-lfsることによって指定したクライアントまで、フルのC#文字列をなしているSQl Server Management Studioクエリに対する反応。
"もういないと表示されます。
"見る"cr-lfs、利用の印刷算書のように:
declare @tmp varchar(500)
select @tmp = msgbody from emailssentlog where id=6769;
print @tmp
こちらはC#の機能がprependsテキスト線既存のテキストblobで区切らCRLFsを返しますT-SQL表現に適した INSERT
または UPDATE
ます。また当社独自のエラー処理ではまさしくその通りなのだが、ripることでするのに役立つかもしれない--そうですね。
/// <summary>
/// Generate a SQL string value expression suitable for INSERT/UPDATE operations that prepends
/// the specified line to an existing block of text, assumed to have \r\n delimiters, and
/// truncate at a maximum length.
/// </summary>
/// <param name="sNewLine">Single text line to be prepended to existing text</param>
/// <param name="sOrigLines">Current text value; assumed to be CRLF-delimited</param>
/// <param name="iMaxLen">Integer field length</param>
/// <returns>String: SQL string expression suitable for INSERT/UPDATE operations. Empty on error.</returns>
private string PrependCommentLine(string sNewLine, String sOrigLines, int iMaxLen)
{
String fn = MethodBase.GetCurrentMethod().Name;
try
{
String [] line_array = sOrigLines.Split("\r\n".ToCharArray());
List<string> orig_lines = new List<string>();
foreach(String orig_line in line_array)
{
if (!String.IsNullOrEmpty(orig_line))
{
orig_lines.Add(orig_line);
}
} // end foreach(original line)
String final_comments = "'" + sNewLine + "' + CHAR(13) + CHAR(10) ";
int cum_length = sNewLine.Length + 2;
foreach(String orig_line in orig_lines)
{
String curline = orig_line;
if (cum_length >= iMaxLen) break; // stop appending if we're already over
if ((cum_length+orig_line.Length+2)>=iMaxLen) // If this one will push us over, truncate and warn:
{
Util.HandleAppErr(this, fn, "Truncating comments: " + orig_line);
curline = orig_line.Substring(0, iMaxLen - (cum_length + 3));
}
final_comments += " + '" + curline + "' + CHAR(13) + CHAR(10) \r\n";
cum_length += orig_line.Length + 2;
} // end foreach(second pass on original lines)
return(final_comments);
} // end main try()
catch(Exception exc)
{
Util.HandleExc(this,fn,exc);
return("");
}
}
だと思う
concat('This is line 1.', 0xd0a, 'This is line 2.')
または
concat(N'This is line 1.', 0xd000a, N'This is line 2.')
これは常に涼しいきの輸出のリストから、Oracle、その記録の複数回線につながるよう期待していますのも面白いのために、履歴書のファイルで注意を。
とにかくRobの答えは良いだを使うよ@,みよう§§@@§§なので、とってもっとも相応しいのかも。(も忘れないでくださの長さ varchar
/nvarchar
分野において挿入す。)