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 |
|
HoffmanGreg
Starting Member
2 Posts |
Posted - 2009-02-27 : 11:42:22
|
| I am banging my head against the wall on this one. It's probably something simple I'm just overlooking. When I run the statement below it writes the same value in every record in CUST_PRICE. UPDATE ITEMSSET CUST_PRICE = ICP.[SELLPRICE] FROM ITEMS ITJOIN ITEM_UNIT IU ON IT.ITEMNO = IU.ITEMNO JOIN ITEM_CUST_PRICE ICPON IU.ITEM_MEASURE_ID = ICP.ITEM_MEASURE_ID WHERE IU.MEAS_TYPE = '1'AND ICP.LEVEL_CODE = '1'Any suggestions?Thanks Greg |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2009-02-27 : 11:56:25
|
quote: Originally posted by HoffmanGreg I am banging my head against the wall on this one. It's probably something simple I'm just overlooking. When I run the statement below it writes the same value in every record in CUST_PRICE. UPDATE ITEMSSET CUST_PRICE = (SELECT ICP.[SELLPRICE] FROM ITEMS ITJOIN ITEM_UNIT IU ON IT.ITEMNO = IU.ITEMNO JOIN ITEM_CUST_PRICE ICPON IU.ITEM_MEASURE_ID = ICP.ITEM_MEASURE_ID WHERE IU.MEAS_TYPE = '1'AND ICP.LEVEL_CODE = '1')Any suggestions?Thanks Greg
See the code in red. I think you have to run a select here...r&r |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-27 : 12:20:39
|
quote: Originally posted by revdnrdy
quote: Originally posted by HoffmanGreg I am banging my head against the wall on this one. It's probably something simple I'm just overlooking. When I run the statement below it writes the same value in every record in CUST_PRICE. UPDATE ITEMSSET CUST_PRICE = (SELECT ICP.[SELLPRICE] FROM ITEMS ITJOIN ITEM_UNIT IU ON IT.ITEMNO = IU.ITEMNO JOIN ITEM_CUST_PRICE ICPON IU.ITEM_MEASURE_ID = ICP.ITEM_MEASURE_ID WHERE IU.MEAS_TYPE = '1'AND ICP.LEVEL_CODE = '1')Any suggestions?Thanks Greg
See the code in red. I think you have to run a select here...r&r
Wouldn't this also update all rows with the same value ??HoffmanGreg, You'd need to post some sample data and output you need to make this clear. |
 |
|
|
HoffmanGreg
Starting Member
2 Posts |
Posted - 2009-02-27 : 14:00:42
|
| I ran it again in Visual Studio, whoch changed my statement to this:UPDATE ITEMSSET CUST_PRICE = ICP.SELLPRICEFROM ITEMS AS ITEMS_1 INNER JOIN ITEM_UNIT AS IU ON ITEMS_1.ITEMNO = IU.ITEMNO INNER JOIN ITEM_CUST_PRICE AS ICP ON IU.ITEM_MEASURE_ID = ICP.ITEM_MEASURE_ID CROSS JOIN ITEMSWHERE (IU.MEAS_TYPE = '1') AND (ICP.LEVEL_CODE = '1')One thing I didn't mention before is that there are 180 records but it tells me that 360 records were updated successfully. Which makes me think that my joins must have a problem. My results came out the same:(I only included a few)ITEMNO CUST_PRICE1.8DuoCoreIntel 20.0000101FGTIPS 20.0000102WHEELS 20.000011-144-057-11 20.00001255 20.00001358 20.0000135834 20.00001468 20.0000I'm sure you know this from the statement, There are not columns that can be joined between the ITEM_CUST_PRICE table and the ITEMS table and that's whyI have to use the ITEM_UNIT table in between the ITEM_CUST_PRICE table and the ITEMS table it has a two different columns that is shares with each table.Two other things come into play. The ITEM_UNIT table has two records for every one record in the items table which I weed outwith the WHERE statement (IU.MEAS_TYPE = '1'). The secondis that the ITEM_CUST_PRICE table has five records for every recordin the ITEMS table and again I thought I took care of that in my WHEREstatement (ICP.LEVEL_CODE = '1').Thanks so much for the help on this. |
 |
|
|
|
|
|