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
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 problem regarding INSERT

Author  Topic 

lamiajoyee
Starting Member

15 Posts

Posted - 2012-01-10 : 10:38:32
hello i need to make a query where i have to insert some data.my problem is that the source of these data are of mixed origins.what i am trying to say is i need to enter explicit data which we insert using the "VALUES" command,and also some data from another table which we usually insert using "SELECT" and "WHERE" commands.how can these two sources of data be merged into a single query?please help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 10:43:02
you can just do like


INSERT INTO Table (col1,Col2,Col3,Col4,...)
SELECT field1,
'A Constant Value',
Field2,
'Another constant value',
...
FROM Yourtable
WHERE condition...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-10 : 10:44:05
insert table(column_a, column_b, column_c)
select
'Myvalue',
column2,
column3
from anotherTable


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-10 : 10:44:27



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -