我想知道如何使用单个列,例如名为ClientID
,我希望能够从两个不同的表中进行选择,并将所有结果都放到此列中。
这是我目前正在尝试但我收到错误:
SELECT ClientID = ('basic' + CAST(a.BasicCID as VARCHAR(15))) AND =('premium' + CAST(c.PremiumCID as VARCHAR(15)))
我希望输出显示类似这样的内容
ClientID Name
------- --------
basic1 John
basic2 Pat
premium1 Mary
premium2 Sean
答案 0 :(得分:2)
好的,你可以这样做 -
Insert into YourTable(ClientID, Name)
SELECT 'basic' + CAST(a.BasicCID as VARCHAR(15)), Name From BasicTable a
UNION
SELECT 'premium' + CAST(c.PremiumCID as VARCHAR(15)), Name From PremiumTable c