-1
DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
DECLARE @STRING VARCHAR(MAX)
    SET @STRING ='SELECT FirstLine AS FL SELECT SecondLine AS SL'
  PRINT LEN(@STRING)
  PRINT @STRING+
        CASE 
          WHEN LEN(@STRING)>2 THEN (@STRING+@NewLineChar)
          ELSE @STRING 
         END
4

1 回答 1

1

我想你正在寻找这个:

DECLARE @Delimiter VarChar(30) = 'SELECT';
DECLARE @NewLineChar AS CHAR(2) = CHAR(13);
DECLARE @STRING VARCHAR(MAX);
    SET @STRING ='SELECT FirstLine AS FL SELECT SecondLine AS SL';

PRINT REPLACE(@STRING, @Delimiter, @NewLineChar + @Delimiter);

输出是:

 SELECT FirstLine AS FL 
 SELECT SecondLine AS SL

我不确定您为什么要寻找比2您要求的输出更大的长度。

于 2013-01-28T13:08:55.073 回答