Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii

i have two tables emp( 3 colums) and empwithcontact (4 columns). i want to copy all records from emp to empwithcontact and in the last column i want to insert "0000" by default. i've tried this... but error occoured (incorrect syntax near 0000)...
SQL
 INSERT INTO [onlineexam].[dbo].[empwithcontact]
           ([id]
           ,[name]
           ,[address]

SELECT  [id]
       ,[name]
       ,[address]
FROM [onlineexam].[dbo].[emp] ,'0000' 
Posted
Comments
Wendelius 7-Sep-11 5:51am    
Are you currently taking this exam ?

Try this.
SQL
INSERT INTO [onlineexam].[dbo].[empwithcontact]
           ([id]
           ,[name]
           ,[address],
           ,[4th_column_name])
 
SELECT  [id]
       ,[name]
       ,[address]
       ,'0000'
FROM [onlineexam].[dbo].[emp] 
 
Share this answer
 
v2
Comments
Wendelius 7-Sep-11 5:58am    
Exactly, just don't forget the closing parenthesis :) I was about to write the same answer, but I hope the OP isn't currently doing the exam..
Toniyo Jackson 7-Sep-11 6:03am    
Thanks Mika. Parenthesis closed. I think he is developing online exam application. :)
Wendelius 7-Sep-11 6:13am    
That could be it, my 5
Toniyo Jackson 7-Sep-11 6:14am    
Thanks Mika :)
INSERT INTO [onlineexam].[dbo].[empwithcontact]
([id]
,[name]
,[address],[4thcolumnname]

SELECT [id]
,[name]
,[address],'0000'
FROM [onlineexam].[dbo].[emp]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900