dbTalk Databases Forums  

Insert into Table Select * from view - Error

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss Insert into Table Select * from view - Error in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
TOM
 
Posts: n/a

Default Insert into Table Select * from view - Error - 10-16-2003 , 09:06 AM






I want to Insert into Table , the Results I am getting from View.

Insert into Table1(col1,col2,col3,...........)

values ( 'Hardcodedvalues',(Select col1+col2 from view),(Select col3+col4 from view),'Hardcodedvalues,.......)

above query is giving me error that It's now allowd in subquery.

Any Idea what is the solution for that.

thanks,
TOM

Reply With Quote
  #2  
Old   
Tibor Karaszi
 
Posts: n/a

Default Re: Insert into Table Select * from view - Error - 10-16-2003 , 09:11 AM






Here is how it should look like:

Insert into Table1(col1,col2,col3,...........)
VALUES SELECT 'Hardcodedvalues',col1+col2, col3+col4, 'Hardcodedvalues' FROM viewname
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver


"TOM" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
I want to Insert into Table , the Results I am getting from View.

Insert into Table1(col1,col2,col3,...........)

values ( 'Hardcodedvalues',(Select col1+col2 from view),(Select col3+col4 from
view),'Hardcodedvalues,.......)

above query is giving me error that It's now allowd in subquery.

Any Idea what is the solution for that.

thanks,
TOM



Reply With Quote
  #3  
Old   
Jacco Schalkwijk
 
Posts: n/a

Default Re: Insert into Table Select * from view - Error - 10-16-2003 , 09:19 AM



Hi Tom,

You can't have a subquery in this case if it returns more than one row. What
you want you can do in the following way:

Insert into Table1(col1,col2,col3,...........)
SELECT 'Hardcodedvalues', col1+col2 , col3+col4, 'Hardcodedvalues'
FROM view

--
Jacco Schalkwijk
SQL Server MVP


"TOM" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
I want to Insert into Table , the Results I am getting from View.

Insert into Table1(col1,col2,col3,...........)

values ( 'Hardcodedvalues',(Select col1+col2 from view),(Select col3+col4
from view),'Hardcodedvalues,.......)

above query is giving me error that It's now allowd in subquery.

Any Idea what is the solution for that.

thanks,
TOM



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.