2014-09-04 155 views
1

我想将5个字符串变量连接成新表中的新字符串。将字符串变量连接到新表中的新变量

SELECT [id],IsNull(Cast(x01 as nvarchar(4000)),'') 
+ IsNull(Cast(x02 as nvarchar(4000)),'') 
+ IsNull(Cast(x03 as nvarchar(4000)),'') 
+ IsNull(Cast(x04 as nvarchar(4000)),'') 
+ IsNull(Cast(x05 as nvarchar(4000)),'') 
INTO newtable 
FROM oldtable AS [id],[new_string]; 

我不明白产生的错误消息,因为我正在创建一个新表 - 列名如何失踪?我期待新表格中有两个变量:id,new_string

对象或列名缺失或为空。对于SELECT INTO语句,验证每个列都有一个名称

+1

它告诉你错误 - 你没有列的名字。添加一个:SELECT [id],... [name] INTO newtable – zimdanen 2014-09-04 15:44:19

回答

0
SELECT [id],IsNull(Cast(x01 as nvarchar(4000)),'') 
+ IsNull(Cast(x02 as nvarchar(4000)),'') 
+ IsNull(Cast(x03 as nvarchar(4000)),'') 
+ IsNull(Cast(x04 as nvarchar(4000)),'') 
+ IsNull(Cast(x05 as nvarchar(4000)),'') as new_string 
           ---------^^^^^^^^^^^^^ 
INTO newtable 
FROM oldtable 

为该列的名称,因此它可以被用来创建新表。