print varchar,某行索引处的行开头

时间:2013-09-12 11:21:58

标签: sql

嗨我想打印那样的东西

                I will start from there 
test this phrase

所以我做了以下

declare @x varchar(max)
select @x = LEFT(' '+'I will start from there',LEN('test this phrase')+ LEN('I will start from there'))+ CHAR(10) + 'test this phrase'

print @x 

输出

 I will start from there
test this phrase

第一行没有从第二行的开头开始,left应该做的但不确定是什么错误

1 个答案:

答案 0 :(得分:2)

尝试使用SPACE功能,如下所示

declare @x varchar(100)
select @x = LEFT(SPACE(LEN('test this phrase')+1)+'I will start from there',LEN('test this phrase')+ LEN('I will start from there'))+ CHAR(10) + 'test this phrase'

print @x