本文介绍了如何在临时表中插入两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DECLARE @Temptable AS TABLE
(
cusname nvarchar(250),
mobno bigint,
address1 nvarchar(350),
address2 nvarchar(350),
state nvarchar(150),
country nvarchar(150),
arrdate nvarchar(150),
depdate nvarchar(150)
)
INSERT INTO @Temptable
--Table 1
SELECT cusname,mobno,address1,address2,state,country FROM cusdetails
--Table 2
SELECT arrdate,depdate FROM roombooked WHERE rid=@rid
and arrdate=(SELECT max(arrdate) FROM roombooked)
SELECT * FROM @Temptable
错误
使用UNION,INTERSECT或EXCEPT运算符组合的所有查询的目标列表中必须具有相同数量的表达式.
Error
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
推荐答案
INSERT INTO @Temptable
SELECT cusname,mobno,address1,address2,state,country,arrdate,depdate FROM cusdetails cd
join roombooked rb on cd.CustId=rb.CustId WHERE rid=@rid
and arrdate=(SELECT max(arrdate) FROM roombooked)
这篇关于如何在临时表中插入两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!