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 |
|
daneil
Starting Member
2 Posts |
Posted - 2010-08-11 : 06:06:52
|
| Hi everyone, can someone help me check my query? i am new to sql and i am using sql express. i found some sources form the internet and come up with this query:-UPDATE InvoicesSET Invoices_1.Corp_DeptID = Invoices.Corp_DeptIDFROM Invoices AS Invoices_1 INNER JOIN Invoices ON Invoices_1.Booking_Ref = Invoices.Booking_Ref AND Invoices_1.Corp_DeptID <> Invoices.Corp_DeptIDWHERE (Invoices.RecType = 0) AND (Invoices.Corp_DeptID <> 0) AND (Invoices_1.Corp_DeptID = 0) AND (Invoices_1.RecType = 11)the execution error says:it says the multi-part "Invoices_1.Corp_DeptID" could not be boundI have an invoice table with this 3 column - booking_ref, Corp_DeptID, RecTypei want to duplicate the same invoice table and update the duplicated table. the conditions are:-invoice table:rectype = 0corp_deptid <> 0duplicate invoice table:rectype = 11corp_id = 0and the 2 table should not have the same corp_deptid and the booking_ref must be the samesomeone help pleaseee =( |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-08-11 : 06:43:28
|
| Simply change the query like below - UPDATE InvoicesSET Invoices.Corp_DeptID = Invoices_1.Corp_DeptIDFROM Invoices AS Invoices_1 INNER JOINInvoices ON Invoices_1.Booking_Ref = Invoices.Booking_Ref AND Invoices_1.Corp_DeptID <> Invoices.Corp_DeptIDWHERE (Invoices.RecType = 0) AND (Invoices.Corp_DeptID <> 0) AND (Invoices_1.Corp_DeptID = 0) AND (Invoices_1.RecType = 11)Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
daneil
Starting Member
2 Posts |
Posted - 2010-08-11 : 21:41:38
|
| Thanks a lot, vaibhavktiwari83. the query you gave posted i tried already. but it change the wrong value. so i changed the condition a bit and it works fine =D cheers~!!UPDATE InvoicesSET Corp_DeptID = Invoices_1.Corp_DeptIDFROM Invoices AS Invoices_1 INNER JOIN Invoices ON Invoices_1.Booking_Ref = Invoices.Booking_Ref AND Invoices_1.Corp_DeptID <> Invoices.Corp_DeptIDWHERE (Invoices.RecType = 11) AND (Invoices.Corp_DeptID = 0) AND (Invoices_1.Corp_DeptID <> 0) AND (Invoices_1.RecType = 0) |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-08-12 : 02:53:46
|
| I dont think this can be differ, I will try it out because i am surprised.Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-08-12 : 03:00:38
|
You have UPDATE Invoicesand thenSET Invoices_1.Corp_DeptIDYou need to update the columns in the table specified in the UPDATE statement. Change toUPDATE Invoices_1orSET Invoices.Corp_DeptIDor justSET Corp_DeptIDwhich will always use the table being updated.For me, using "Invoices" table twice in the query I would give an alias to both tables, and use the Alias Name in the UPDATE statement (we traditionally use the alias "U" for the table being updated |
 |
|
|
|
|
|