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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column names

Author  Topic 

maggie21620
Starting Member

27 Posts

Posted - 2014-01-16 : 13:13:16
i have a qry:
SELECT DISTINCT ACCTCORP, BXSTATUS
FROM dbo.IDST_BOX_INVENTORY

which gives me
bxstatus corps
A 9527
B 1620
B 6101
C 6101
C 9568
D 9540
D 9568

what 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 bxstatusDescription
FROM dbo.IDST_BOX_INVENTORY
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -