SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert into table with more data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shanmugaraj
Posting Yak Master

212 Posts

Posted - 05/14/2013 :  03:10:46  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
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

Edited by - shanmugaraj on 05/14/2013 03:26:24

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 05/14/2013 :  03:41:37  Show Profile  Reply with Quote

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


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000