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 |
underwms
Starting Member
2 Posts |
Posted - 2007-09-13 : 11:26:43
|
Can anybody tell me why this works?UPDATE podSET pod.warehouse_id = pom.warehouse_idFROM #temp_po_detail AS pod (NOLOCK) JOIN #temp_po_master AS pom (NOLOCK) ON pom.po_number = pod.po_numberAnd this doesn'tUPDATE #temp_po_detailSET warehouse_id = (SELECT TOP 1 pom.warehosue_id) FROM #temp_po_detail AS pod (NOLOCK) JOIN #temp_po_master AS pom (NOLOCK) ON pom.po_number = pod.po_number)Some background: this is for a warehouse inventory system; inside pom is the master data about the PO and pod has the details such as line items. |
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-13 : 11:30:29
|
What error do you get? Did you mis-type: SELECT TOP 1 pom.warehosue_id? Future guru in the making. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-13 : 11:31:30
|
[code]UPDATE podSET pod.warehouse_id = pom.warehouse_idFROM #temp_po_detail AS pod (NOLOCK)inner JOIN #temp_po_master AS pom (NOLOCK) ON pom.po_number = pod.po_numberUPDATE #temp_po_detailSET warehouse_id = (SELECT TOP 1 pom.warehosue_id) -- here is wrong syntaxFROM #temp_po_detail AS pod (NOLOCK)/* This part is not needed since yuo are using a correlated subquery aboveJOIN#temp_po_master AS pom (NOLOCK)ON pom.po_number = pod.po_number)*/This would be the correcte syntax for second update statementUPDATE #temp_po_detailSET warehouse_id = (SELECT TOP 1 pom.warehosue_id FROM #temp_po_detail AS pod (NOLOCK) WHERE #temp_po_detail.po_number = pod.po_number)[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
underwms
Starting Member
2 Posts |
Posted - 2007-09-13 : 11:35:15
|
sorry my syntax is off here it is properWhy does this work?UPDATE podSET pod.warehouse_id = pom.warehouse_idFROM #temp_po_detail AS pod (NOLOCK) JOIN #temp_po_master AS pom (NOLOCK) ON pod.po_number = pom.po_numberAnd this doesn'tUPDATE #temp_po_detailSET warehouse_id = (SELECT TOP 1 pom.warehouse_id FROM #temp_po_detail AS pod JOIN #temp_po_master AS pom ON pod.po_number = pom.po_number WHERE pod.po_number = pom.po_number) |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-13 : 11:49:07
|
The second query do not need an extra join. The query parser already knows which record it works with.Please feel free to ignore my previous explanation... E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|