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 2000 Forums
 Transact-SQL (2000)
 Insert Into where...

Author  Topic 

Rauken
Posting Yak Master

108 Posts

Posted - 2005-08-31 : 17:54:07
It's getting late here in Sweden maybe that's why I'm stuck.

I have 2 tables, let's say a invoice table and a invoice_item table. 30 of my invoices does not have any invoice_items connected. I want to add a invoice_item for all 30. Something like this...

INSERT INTO invoice_item (itemno, price) VALUES (9999, 10)
WHERE InvoiceDoesNotHaveInvoiceItems...

Any fast solution?

VIG
Yak Posting Veteran

86 Posts

Posted - 2005-08-31 : 18:33:04
[code]insert invoice_item (itemno, price)
select 9999,10
from invoice i
left join invoice_item it on i.itemno=it.itemno
where it.itemno is null[/code]
but may be you want
[code]insert invoice_item (itemno, price)
select i.itemno,10
from invoice i
left join invoice_item it on i.itemno=it.itemno
where it.itemno is null[/code]
Go to Top of Page

Rauken
Posting Yak Master

108 Posts

Posted - 2005-08-31 : 19:00:06
Thanks, it's the first one I'm after. It feels a little bit akward to write select 9999, 10 from invoice but it works.
Go to Top of Page
   

- Advertisement -