| Author |
Topic |
|
sfs00784
Starting Member
4 Posts |
Posted - 2007-11-29 : 02:13:55
|
| I don't know how to return the sum of Quantity_held, can somebody help me?Thanks.SELECT Item.Item_id, Item.Description, Hold.Quantity_heldFROM Item, Hold, ConsistWHERE Item.Item_id = 2 AND Item.Item_id = Hold.Item_id AND Item.Item_id = Consist.Item_id AND Consist.City_id = 5Item_id Description Quantity_held----------- ------------------- -------------2 Chang 502 Chang 82 Chang 12 Chang 22 Chang 3(5 row(s) affected) |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2007-11-29 : 02:32:48
|
| SELECT Item.Item_id, Item.Description, SUM(Hold.Quantity_held) AS Quantity_heldFROM Item, Hold, ConsistWHERE Item.Item_id = 2AND Item.Item_id = Hold.Item_idAND Item.Item_id = Consist.Item_idAND Consist.City_id = 5GROUP BY Item.Item_id, Item.Description |
 |
|
|
sfs00784
Starting Member
4 Posts |
Posted - 2007-11-29 : 02:47:27
|
quote: Originally posted by PeterNeo SELECT Item.Item_id, Item.Description, SUM(Hold.Quantity_held) AS Quantity_heldFROM Item, Hold, ConsistWHERE Item.Item_id = 2AND Item.Item_id = Hold.Item_idAND Item.Item_id = Consist.Item_idAND Consist.City_id = 5GROUP BY Item.Item_id, Item.Description
Thanks for your reply, the problem is that my Item.Description is ntext. Or I should use nvarchar(MAX) for that...Msg 306, Level 16, State 2, Line 1The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-29 : 03:27:30
|
| or instead of Item.Description use cast(Item.Description as nvarchar(max))MadhivananFailing to plan is Planning to fail |
 |
|
|
arorarahul.0688
Posting Yak Master
125 Posts |
Posted - 2007-11-29 : 06:33:08
|
| try this SELECT i.Item_id, i.Description, h.Quantity_heldFROM Item i inner join Hold h i.Item_id = h.Item_id inner join consist c oni.Item_id = c.Item_idWHERE Item.Item_id = 2and Consist.City_id = 5Rahul Arora MCA 07 BatchNCCE Israna, PanipatHRY, INDIA######################IMPOSSIBLE = I+M+POSSIBLE |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2007-11-29 : 06:37:19
|
i think you must have misread the question, no? and not read the replies... again?quote: Posted - 11/29/2007 : 06:33:08 -------------------------------------------------------------------------------- try thisSELECT i.Item_id, i.Description, h.Quantity_heldFROM Item i inner join Hold h i.Item_id = h.Item_id inner join consist c oni.Item_id = c.Item_idWHERE Item.Item_id = 2and Consist.City_id = 5Rahul Arora
Em |
 |
|
|
KenW
Constraint Violating Yak Guru
391 Posts |
Posted - 2007-11-29 : 16:21:29
|
quote: Originally posted by elancaster i think you must have misread the question, no? and not read the replies... again?Em
Again? Don't you mean still? Rahul Arora hasn't answered a single question correctly, as far as I can see. Definitely doing more harm than good here - the wrong answers may lead people astray. |
 |
|
|
arorarahul.0688
Posting Yak Master
125 Posts |
Posted - 2007-11-30 : 01:51:42
|
quote: Originally posted by elancaster i think you must have misread the question, no? and not read the replies... again?quote: Posted - 11/29/2007 : 06:33:08 -------------------------------------------------------------------------------- try thisSELECT i.Item_id, i.Description, h.Quantity_heldFROM Item i inner join Hold h i.Item_id = h.Item_id inner join consist c oni.Item_id = c.Item_idWHERE Item.Item_id = 2and Consist.City_id = 5Rahul Arora
Em
yeah i m sorry i just misread and thoght to use join instead of simple comparison thats wahy i forgot to use group by to sum up hold.quantity corresponding to item_id,description. Rahul Arora MCA 07 BatchNCCE Israna, PanipatHRY, INDIA######################IMPOSSIBLE = I+M+POSSIBLE |
 |
|
|
arorarahul.0688
Posting Yak Master
125 Posts |
Posted - 2007-11-30 : 01:58:29
|
quote: Originally posted by KenW
quote: Originally posted by elancaster i think you must have misread the question, no? and not read the replies... again?Em
Again? Don't you mean still? Rahul Arora hasn't answered a single question correctly, as far as I can see. Definitely doing more harm than good here - the wrong answers may lead people astray.
hi kenw iknow you have seen two answers and saing Rahul Arora hasn't answered a single question correctly, as far as I can see.you don't have any right to make such statement and even you are not a superman ok. i am trying this to improve my logics if you think its wrong then straight tell me its wrong i wouldn't mind as i am not much known to sql server. and belive untill unless you commit a mistake you willwill not learn muchRahul Arora MCA 07 BatchNCCE Israna, PanipatHRY, INDIA######################IMPOSSIBLE = I+M+POSSIBLE |
 |
|
|
|