代码之家  ›  专栏  ›  技术社区  ›  Jamie Marshall

不带缩进字符的T-SQL多行字符串

  •  1
  • Jamie Marshall  · 技术社区  · 6 年前

    这似乎很简单…

    如何存储多行字符串以使代码保持良好的格式。

    这样做很难看

    DECLARE @myStr NVARCHAR(MAX)
    SET @myStr = 'This represents a really long
    string that i need multiple lines for,
    dude.'
    

    但上述结果会产生正确的字符串输出:

    SELECT @myStr
    'This represents a really long string that i need multiple lines for, dude.'
    

    这样做可以更容易地阅读我的代码:

    DECLARE @myStr NVARCHAR(MAX)
    SET @myStr = 'This represents a really long
        string that i need multiple lines for,
        dude.'
    

    但结果是:

    SELECT @myStr
    'This represents a really long     string that i need multiple lines for, 
    dude.'
    

    在多行字符串中是否有特殊的方法来转义制表符(就像其他语言一样…)

    1 回复  |  直到 6 年前
        1
  •  3
  •   paulsm4    6 年前

    你在找一个 backslash (“\”):

    SET @myStr = 'This represents a really long \
        string that i need multiple lines for, \
        dude.'