当我将常量字符串添加为字段时,出现错误消息
这是错误消息:
我想将表名作为列添加到SQL视图中的行中,出现错误消息:
已执行的SQL语句:
[...]
错误来源:.Net SQL客户端数据提供程序
错误消息:所有使用UNION,INTERSECT或EXCEPT运算符组合的查询必须具有相同数量的表达式及其目标列表。
SELECT Location, ClientID, Type_C, Todays_Date, '1100_vAC' as S_Table
FROM dbo.1100_vAC
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1100_vAD' as S_Table
FROM dbo.1100_vAD
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1101_AC' as S_Table
FROM dbo.1101_AC
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1101_AA' as S_Table
FROM dbo.1101_AA
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1102_AC' as S_Table
FROM dbo.1102_AC;
我想为每一行查看源表。
答案 0 :(得分:0)
您应该更正您的代码(删除重复的time_stamp)
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1100_vAC' as S_Table
FROM dbo.1100_vAC
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1100_vAD' as S_Table
FROM dbo.1100_vAD
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1101_AC' as S_Table
FROM dbo.1101_AC
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1101_AA' as S_Table
FROM dbo.1101_AA
UNION ALL
SELECT Location, ClientID, Type_C, Todays_Date, Time_Stamp, '1102_AC' as S_Table
FROM dbo.1102_AC;
答案 1 :(得分:0)
联合,相交和除外需要相同数量的列(最好也有顺序)。在除了第一个选择的所有选择上都复制了TIMESTAMP的过程中出现了一个错误。
答案 2 :(得分:0)
第一行包含6列,其余行包含7列,因为在其余各行中增加了一个额外的时间戳列。
Union / union都联合数据而不是它联接的列。因此,您还需要保留与类型相同的列数,以确保整个数据同步且一致