SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 count function - how many rows for each OR cond
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chauhan.shaili
Starting Member

1 Posts

Posted - 02/21/2013 :  10:01:38  Show Profile  Reply with Quote
Hi,
I have following query (there are 3 rows with emp id= 1234, and 2 with 5678)
Select EMP_ID from EMPLOYEE
where EMP_ID = '1234' OR EMP_ID = '5678'
Out put
EMP_ID
------
1234
1234
1234
5678
5678
In above query is it possible to select a static/constant colum with a flag so that it flags like
EMP_ID MY_FLAG
------ -------
1234 A
1234 A
1234 A
5678 B
5678 B

obedrodriguez
Starting Member

9 Posts

Posted - 02/21/2013 :  10:12:53  Show Profile  Reply with Quote
Select
EMP_ID,
CASE EMP_ID WHEN '1234' then 'A' WHEN '5678' then 'B' END AS 'MY_FLAG'
FROM EMPLOYEE
where EMP_ID = '1234' OR EMP_ID = '5678'

Edited by - obedrodriguez on 02/21/2013 10:13:43
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/21/2013 :  22:27:27  Show Profile  Reply with Quote
are you looking at generating flags automatically for each emp_ID. then solution should be like below:-

SELECT EMP_ID,CHAR(64 + DENSE_RANK() OVER (ORDER BY EMP_ID))
FROM table


question is how do you want values to come if there are more than 26 distinct ids so that alphabets are finished!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000