【问题标题】:Concatenate string variables into a new variable in new table将字符串变量连接到新表中的新变量中
【发布时间】:2014-09-04 15:42:23
【问题描述】:

我正在尝试将 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 语句,验证每一列都有一个名称

【问题讨论】:

  • 它告诉您错误 - 您没有列的名称。加一:SELECT [id], ... [name] INTO newtable

标签: sql select casting isnull select-into


【解决方案1】:
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

为列命名,以便用于创建新表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    相关资源
    最近更新 更多