Use Condition (IF OR Case ) in SQL Statment
-
02 Mei 2012 12:43
I want use condition if Column Null And Other Condition Like ID=X
Select From Another Column
Ahmed Osman
Semua Balasan
-
02 Mei 2012 12:56
Use the CASE expression:SELECT CASE WHEN Column IS NULL AND ID = X THEN Column1 ELSE Column2 END FROM yourTable;
- Diedit oleh Stefan HoffmannMVP 02 Mei 2012 12:57
- Disarankan sebagai Jawaban oleh Elmozamil Elamir 03 Mei 2012 6:49
- Ditandai sebagai Jawaban oleh Ahmed Osman2 03 Mei 2012 10:43
-
02 Mei 2012 13:09Moderator
Hello,
You have forgotten to tell us for which DBMS (SQL Server , ORACLE, ACCESS). The version and edition could be also usefull
For SQL Server :
- test if a column is null ==> ISNULL http://msdn.microsoft.com/en-us/library/ms184325(SQL.100).aspx ( for SQL Server 2008 valid from 2005 )
have a look at http://msdn.microsoft.com/en-us/library/ms191270(SQL.100).aspx ( a comparaisn to null is not evident to understand )
- for AND operator : http://msdn.microsoft.com/en-us/library/ms189119(SQL.100).aspx
Please, could you provide the definition of your table and explain "Other Condition Like" ?
LIKE is existing in TRANSACT-SQL ( pattern matching in search ) http://msdn.microsoft.com/en-us/library/ms187489(SQL.100).aspx
Don't hesitate to post again for more help or explaination
Have a nice day
PS : if your thread is related to SQL Server , it is possible that a moderator moves your thread towards the Transact-SQL forum where it will interest more people ( this forum is mainly for connection or protocols problems )
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
-
03 Mei 2012 10:43
Thanks Stefan Hoffmann
thats Help me
Ahmed Osman