sql - Inserting into two colums in a temp table with 2 different subqueries -
is possible insert info 2 colums in temp table 2 different subqueries?
i have tried following
create table #temp ( fromplaninvtid bigint ,toplaninvtid bigint ) insert #temp ( fromplaninvtid ,toplaninvtid ) values ( (select planinvtid pr_planinvestments planid = 65) ,(select planinvtid pr_planinvestments planid = 214) ) here both subqueries returns more 1 value
is there other way this?
yes. utilize insert . . . select:
insert #temp (fromplaninvtid, toplaninvtid) select (select planinvtid pr_planinvestments planid = 65), (select planinvtid pr_planinvestments planid = 214); this assumes each subquery returns @ 1 row. otherwise, error effect "subquery returns more 1 row".
edit:
if subqueries homecoming more 1 value, can combinations with:
insert #temp (fromplaninvtid, toplaninvtid) select t1.planinvtid , t2.planinvtid (select planinvtid pr_planinvestments planid = 65 ) t1 cross bring together (select planinvtid pr_planinvestments planid = 214 ) t2; sql sql-server
No comments:
Post a Comment