Avatar of Seven price
Seven price
Flag for United States of America asked on

insert using where clause.

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
Microsoft SQL Server 2005Microsoft SQL Server

Avatar of undefined
Last Comment
HomerTNachoCheese

8/22/2022 - Mon
HomerTNachoCheese

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 )
SELECT table2.store
FROM table2
WHERE (((table2.userid)=419))
santhimurthyd

I'm not clear on your question, but below Syntax will help up to insert record of userid = 419 from table2 to table1

INSERT INTO table1
select store from table2 where userid = 419
Seven price

ASKER
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

example

table 1

userid   storeid
419        store1
419        store2
419        store3
419        store4

table2 where I need to select all stores is just
storeid
store1
store2
store3
store4
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
HomerTNachoCheese

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Seven price

ASKER
work great
HomerTNachoCheese

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