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 2005 Forums
 Transact-SQL (2005)
 INSERT statement not working

Author  Topic 

rum23
Yak Posting Veteran

77 Posts

Posted - 2009-01-27 : 13:27:46

Can you please tell me what is wrong in this sql statement?

INSERT INTO tblB(ID1, ID2, BudgetDate)
VALUES (SELECT ID1, ID2, GetDate() as BudgetDate FROM tblA)

I get 2 errors on executing this sql

1. Incorrect syntax near the keyword 'SELECT'.
2. Incorrect syntax near ')'.

Thanks for your help

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-27 : 13:29:40
[code]SELECT ID1, ID2, GetDate() as BudgetDate
into tblb
FROM tblA[/code]

or if table exists
[code]INSERT INTO tblB(ID1, ID2, BudgetDate)
SELECT ID1, ID2, GetDate() as BudgetDate FROM tblA[/code]
Go to Top of Page

rum23
Yak Posting Veteran

77 Posts

Posted - 2009-01-27 : 13:32:35

hmm...that doesn't work because it tries to create tblB and tblB already exists. I basically want to get all the rows from tblA and insert them into tblB.
Go to Top of Page

rum23
Yak Posting Veteran

77 Posts

Posted - 2009-01-27 : 13:33:53
oops! nevermind. Ignore my response.


INSERT INTO tblB(ID1, ID2, BudgetDate)
SELECT ID1, ID2, GetDate() as BudgetDate FROM tblA

Worked!

Thanks.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-27 : 13:35:32
Put that query in Export/Import wizard instead for faster insert.
Go to Top of Page
   

- Advertisement -