SELECT S.Id, S.Name, S.Version, S.SoftNo
FROM SOFTWARE S WITH(NOLOCK)
WHERE (IF S.Version = 0 THEN S.Version > 0 ELSE S.Version = @Version)
AND (IF S.SoftNo = 0 THEN S.SoftNo > 0 ELSE S.SoftNo = @SoftNo)
如果Version等於零,我想列出所有的版本號大於0,如果它不等於0,那麼Version應該是它的任何值。IF ELSE SQL中的語句
這與SoftNo相同。
我該如何解決我的SQL查詢問題。它只是不起作用。
更多細節:
這就是我想實現:
if(Version == 0)
{
display every single rows if their version number is greater then 0;
}
else
{
Lets assume that Version is equal to 5. Then just display the rows if their Version number is equal to 5;
} // This is like a C# code of what I am trying to do in my sql query.
System.Data.SqlClient.SqlException(0x80131904):關鍵字'IF'附近的語法不正確。在關鍵字'THEN'附近有錯誤的語法。在關鍵字'THEN'附近有錯誤的語法。 – 2012-03-26 09:54:52
http://stackoverflow.com/questions/63447/how-do-you-perform-an-if-then-in-an-sql-select – assylias 2012-03-26 09:57:19