Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert into table with more data

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-05-14 : 03:10:46
I need to insert an result into my main table.

Insert into main_table
(country_id, state_id
)
(
(SELECT distinct country_id from [dim_country]) ,
(SELECT distinct state_id from [dim_state])
)

Expected Result
===================
1 | 101
1 | 102
1 | 103
ERROR
Msg 512, Level 16, State 1, Line 2
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-14 : 03:41:37
[code]
Insert into main_table
(country_id, state_id
)
SELECT country_id,state_id
FROM
(
SELECT distinct country_id from [dim_country]
)c
CROSS JOIN
(
SELECT distinct state_id from [dim_state]
)s
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -