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 |
maggie21620
Starting Member
27 Posts |
Posted - 2014-01-16 : 13:13:16
|
i have a qry:SELECT DISTINCT ACCTCORP, BXSTATUSFROM dbo.IDST_BOX_INVENTORYwhich gives me bxstatus corpsA 9527B 1620B 6101C 6101C 9568D 9540D 9568what i want to do is add the definition of what each bxstatus is to the results, ex: a = 'test_new'none |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-01-16 : 13:17:39
|
If you have a reference table that lists the descriptions, you can join to that table. If you don't have something like that, then like this:SELECT DISTINCT ACCTCORP, BXSTATUS,CASE bxstatus WHEN 'A' then 'test_new' WHEN 'B' then 'test_not_so_new' WHEN 'C' then 'test_old' ELSE 'Unknown_test'END as bxstatusDescriptionFROM dbo.IDST_BOX_INVENTORY |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-16 : 14:03:48
|
I would prefer creating a mapping table for this as that would be more scalableand maintainable in future ie whenever you've a new description and bxstatus you can just add a record to table and join to that rather than changing numerous places where you would have implemented similar case..when logics.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|