insert using where clause.

Seven price
Seven price used Ask the Experts™
INSERT INTO table1 where userid = 419

select store from table2

how can I select from one table and insert into another but using a where clause in the insert statement. this way it will only insert where the userid is 419
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I am assuming both table1 and table2 both have a field called store.  If table1 is using a different field name, change store in the first line to whatever that field name is.

You may need to change 419 to '419'

INSERT INTO [table1] ( store )
FROM table2
WHERE (((table2.userid)=419))
I'm not clear on your question, but below Syntax will help up to insert record of userid = 419 from table2 to table1

select store from table2 where userid = 419
Seven priceFull Stack


well table2 I need to select all stores and insert them into table 1 but table 1 has multiply stores so I must insert all stores but insert them with row value 419


table 1

userid   storeid
419        store1
419        store2
419        store3
419        store4

table2 where I need to select all stores is just
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Is the userid 419 in table2, or are you just dumping all data from table2 into table1 and adding userid 419 at the same time?  If that is the case, then do this:

INSERT INTO [table1] ( userid, store )
SELECT '419 as userid,
FROM table2

My queries I am giving you are from MS Access - but they should be nearly the same for SQL Server.
Seven priceFull Stack


work great
I had a typo in that last one, glad you figured it out!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial