Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
E_ID     E_IP         E_TYPE
E00003	192.168.0.131	E
E00003	192.168.0.131	B
E00003	192.168.0.131	B
E00003	192.168.0.131	E
E00003	192.168.0.131	E
E00003	192.168.0.131	B
E00003	192.168.0.131	X
	192.168.0.131	X
E00003	192.168.0.131	E
E00004	192.168.0.131	B


I want select sql query using IF condition...If the E_TYPE Column is E and B i want to display the rows of E and B and if E_TYPE column is X i want to display the X rows only....
Posted
Comments
Bala Selvanayagam 1-Oct-11 10:08am    
Your required output of the above question is not clear...can you please go into more detail

There is not IF condition in SQL but you may have to use CASE statement...just google for the "SQL case statement".....

1 solution

Not sure what you mean, but here is how to use IF... ELSE in SQL[^].
In a SELECT statement it would probably be better and easier to use CASE WHEN... THEN... ELSE...[^].
The MSDN documentation on these is actually pretty good, complete with examples. So I am not going to explain them again here. Simply check out the links and you should manage :)
 
Share this answer
 
Comments
Simon Bang Terkildsen 1-Oct-11 13:12pm    
+5It would not only be better and easier to use CASE in a select statement, it's the only option as you can't use if-else in a select statement.
Sander Rossel 1-Oct-11 13:51pm    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900