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
 General SQL Server Forums
 New to SQL Server Programming
 Insert infor from 1 table to another

Author  Topic 

jatrix32
Starting Member

49 Posts

Posted - 2010-09-17 : 09:59:56
I have to insert info from 1 table to another, but also have to include some hard coded info. There are 4 fields total, and over 1,000 records.

Here is my query:

INSERT INTO Account_User_Groups
(sub_id,
account_id,
group_id,
active)
VALUES
('info.othertable',
'291',
'info.othertable',
'1')

I need this query to insert all 1000 records. I know how to run this if it was a straight insert from 1 table to another, but having to add in hardcoded values is throwing me off.

rohitvishwakarma
Posting Yak Master

232 Posts

Posted - 2010-09-17 : 10:17:12
I those harcoded values are going to be same for all rows then :



INSERT INTO Account_User_Groups
(sub_id,account_id,group_id,active)
VALUES (SELECT sub_id FROM TABLE2),'291',(SELECT group_id FROM TABLE2),'1')
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-09-17 : 10:19:05
INSERT INTO Account_User_Groups(sub_id,account_id,group_id,active)
SELECT info1, 291, info2, 1 FROM othertable

I dont know this reaches upto your requirement or not?

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

jatrix32
Starting Member

49 Posts

Posted - 2010-09-17 : 10:50:30
both are money, thanks for all the help!!!!
Go to Top of Page
   

- Advertisement -