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
 count function - how many rows for each OR cond

Author  Topic 

chauhan.shaili
Starting Member

1 Post

Posted - 2013-02-21 : 10:01:38
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 - 2013-02-21 : 10:12:53
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'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-21 : 22:27:27
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
   

- Advertisement -