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 |
|
anti-rich
Starting Member
14 Posts |
Posted - 2007-05-15 : 02:37:43
|
hi all,i am designing a query in sql2k5 for a report which will print out pickup stats for my warehouse. every item will have an item code (and items come in and out of the warehouse frequently, with the item being deleted off the warehouse's db when there are 0 stock), but because of the limited data i am being given, i wont always have a complete description of the item. i thought it would be wise to use a left outer join in my query, so a complete list of everything that is picked will show up on the stats, as well as how often the item (with missing data) is picked. so... here is what i have so farSELECT CASE n.Description WHEN n.Description IS NULL THEN 'Unknown' ELSE n.Description END AS [Item Description], COUNT(w.Qty) AS [Times Picked], SUM(w.Qty) AS [Volume Picked], w.ItemID, f.LocationsFROM tblWT w LEFT OUTER JOIN tblItem n ON w.ItemID= n.ItemID LEFT OUTER JOIN dbo.fReturnAllLocations(0) f ON n.ItemID= f.ItemIDGROUP BY n.Description, w.ItemID, f.LocationsORDER BY [Times Picked] DESC, [Volume Picked] DESC ok, so the wierd thing of this problem is the case statement... it just refuses to evaluate, spitting out the error of 'Incorrect syntax near the keyword 'IS''. i dont understand why this is happening, as everything seems to be ok (to my eyes)... perhaps i am missing something. if someone could point it out i would be really grateful :)cheersadam |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-15 : 02:47:48
|
quote: Originally posted by anti-rich hi all,i am designing a query in sql2k5 for a report which will print out pickup stats for my warehouse. every item will have an item code (and items come in and out of the warehouse frequently, with the item being deleted off the warehouse's db when there are 0 stock), but because of the limited data i am being given, i wont always have a complete description of the item. i thought it would be wise to use a left outer join in my query, so a complete list of everything that is picked will show up on the stats, as well as how often the item (with missing data) is picked. so... here is what i have so farSELECT CASE n.Description WHEN n.Description IS NULL THEN 'Unknown' ELSE n.Description END AS [Item Description], COUNT(w.Qty) AS [Times Picked], SUM(w.Qty) AS [Volume Picked], w.ItemID, f.LocationsFROM tblWT w LEFT OUTER JOIN tblItem n ON w.ItemID= n.ItemID LEFT OUTER JOIN dbo.fReturnAllLocations(0) f ON n.ItemID= f.ItemIDGROUP BY n.Description, w.ItemID, f.LocationsORDER BY [Times Picked] DESC, [Volume Picked] DESC ok, so the wierd thing of this problem is the case statement... it just refuses to evaluate, spitting out the error of 'Incorrect syntax near the keyword 'IS''. i dont understand why this is happening, as everything seems to be ok (to my eyes)... perhaps i am missing something. if someone could point it out i would be really grateful :)cheersadam
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-15 : 02:49:21
|
or simply use COALESCE:SELECT COALESCE(n.Description, 'UNKNOWN') AS [Item Description] Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
anti-rich
Starting Member
14 Posts |
Posted - 2007-05-15 : 02:55:08
|
| ah i see... well i didnt realise that! haha,thank you so much harsh, your help is greatly appreciatedhave a good day :) (or night... depending where you are)regardsadam |
 |
|
|
|
|
|
|
|