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 |
|
archana23
Yak Posting Veteran
89 Posts |
Posted - 2012-06-04 : 10:09:22
|
| Hi,i have written one simple query to retrive items information from each location.SELECT DISTINCT CASE Location WHEN 'Tx' THEN 'TEXAS'WHEN 'NJ' THEN 'New Jersy' WHEN 'NC' THEN 'North Carolina' ELSE 'OTHER' END AS Location, Items FROM ItemsByLocation where date= @dateFrom above query i am getting data for each location.but For example if Location NJ has no rows for that particular datethen i am getting like Location Items TEXAS 120 North Carolina 75Its not retruning any row for Location New Jercy bcoz it has no items but according to my requirement it should return with items as Zero values Location Items TEXAS 120 North Carolina 75 New Jercy 0Can you please help me on this..Archana |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-04 : 10:23:32
|
you need to have a master table for locations likeLocation LocCodeTEXAS TxNewJersey NJNorth Carolina NC....and then use like SELECT lm.Location, COALESCE(i.Items ,0) AS ItemsFROM LocationMaster lmLEFT JOIN ItemsByLocation iON i.Location = lm.LocCodeAND i.date= @date ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
archana23
Yak Posting Veteran
89 Posts |
Posted - 2012-06-04 : 10:30:05
|
| Thanks for reply.I dont want to get zero's for other locations. I need to show zero for only NJ location.Thanks..Archana |
 |
|
|
|
|
|