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.
| Author |
Topic |
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2009-04-26 : 09:34:40
|
I'm trying to run the one off code below to update a few records but get the above error. Here's the code, can you see what's wrong?DECLARE @invoice_ID intDECLARE db_cursor CURSOR FOR select invoices.idfrom income inner join invoices on income.invoiceid = invoices.idwhere isdate(invoices.paid_date) = 0 and on_bank_statement=1OPEN db_cursor FETCH NEXT FROM db_cursorINTO @invoice_IDWHILE @@FETCH_STATUS = 0 BEGIN update income set on_bank_statement=0 where invoiceid = @invoice_IDgoFETCH NEXT FROM db_cursorINTO @invoice_IDEND CLOSE db_cursor DEALLOCATE db_cursor |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-04-26 : 10:59:56
|
Your @invoice_ID is not known after you type a "go".Take away that "go".Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2009-04-26 : 11:03:15
|
| Excellent, thanks for that! |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-04-26 : 11:06:13
|
Why not just do:UPDATE inc SET on_bank_statement=0FROM income incINNER JOIN invoices inv on inc.invoiceid=inv.idwhere isdate(inv.paid_date)=0 and inc.on_bank_statement=1 |
 |
|
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2009-04-26 : 11:14:50
|
| I wasn't sure of the update syntax with inner join in so I found a cursor example and tweaked it.I only needed to run it the once |
 |
|
|
|
|
|