I am working on databases and now I need some advice’s from you guys..
I have 2 Tables with many rows and columns and these db’s contain addresses of customers. Names of the tables are Data, Orders.
Now the problem is I have to search the addresses present in Table Orders with the addresses in Data using email as the criteria.
If there is a match in emails then its ok….or else we should insert the addresses of the table Orders in table Data. …
I made this query but i am getting some error.
INSERT INTO orders (orders_id, customers_id, customers_cid, customers_vat_id, customers_name, customers_email_address) VALUES( (select o.* from Test.dbo.orders o where o.customers_email_address not in ( select a.email0 from CobraDemoData.dbo.Data a)))
Any help is much appreciated..
Thanks,
subash
You can insert the values directly from a select statement–don’t use
valueswhen you want to do that. Additionally, you can usenot existsin lieu ofnot in, as SQL Server usually runs that much faster, but it’s case-by-case, so you can look at the query plan if it’s really an issue.Also, you probably want to specify the columns in the select statement, just to make sure the right columns are transposed.