打印中的varchar(max)变量的不同输出,并在SQL Server

时间:2015-12-23 18:12:40

标签: sql-server sql-server-2008 tsql

我们在这种情况下声明了varchar(max)变量,并在此之后分配了数据,以便将该值插入表中以供进一步使用。但是当我们选择数据时,我们得到了截断的数据。

declare @check varchar(max)

set @check = 'Calc saves your document as a file in your file system. If you open such a file in a plain text editor, you will immediately see that it is an XML document. Look at this plain file and find out where the interesting data is located. Target those elements with XSLT templates. Please note: I can only point you in the right direction, your question as such is too vague and broad for Stackoverflow.'
print @check 
select @check 

结果:

Calc saves your document as a file in your file system. If you open such a file in a plain text editor, you will immediately see that it is an XML document. Look at this plain file and find out where the interesting data is located. Target those elements with XSLT templates. Please note: I can only point you in the right direction, your question as such is too vague and broad for Stackoverflow.

Calc saves your document as a file in your file system. If you open such a file in a plain text editor, you will immediately see that it is an XML document. Look at this plain file and find out where the interesting data is located. Target those elements w

(1 row(s) affected)

输出select @check正在给出截断结果。我想使用select @check插入表格。有任何解决方法吗?

2 个答案:

答案 0 :(得分:5)

它被截断,因为Management Studio不一定会将完整值输出到屏幕,并且默认显示宽度为256个字符,这是您发生截止的地方:

SSMS Options screen

变量本身的值不受影响。

答案 1 :(得分:0)

不要担心这不会反映现场数据。您仍然可以使用select插入到表中,您将拥有该字段的全部内容。

运行以下代码来证明这一点

declare @check varchar(max)

set @check = 'Calc saves your document as a file in your file system. If you open such a file in a plain text editor, you will immediately see that it is an XML document. Look at this plain file and find out where the interesting data is located. Target those elements with XSLT templates. Please note: I can only point you in the right direction, your question as such is too vague and broad for Stackoverflow.'
print @check 
select @check 

create table #temp ([check] varchar(max))

insert into #temp
select @check 

select LEN(@check),LEN([check]) FROM #temp