我想將C#if語句轉換爲SQL Server if語句,以便我可以在SQL Server語句中使用它來基於此條件篩選記錄。如果將語句轉換爲SQL Server語句
public bool checkSourceSystem(bool A, bool B, bool C, string SendToA, string SendToB, string SendToC)
{
int count = 0;
if (A == true || B == true || C == true)
{
if(A == true && SendToA == "Success")
{
count++;
}
else
{
return false;
}
if(B == true && SendToB== "Success")
{
count++;
}
else
{
return false;
}
if (C == true && SendToC == "Success")
{
count++;
}
else
{
return false;
}
}
else
{
return false;
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
}
}
我沒有按下面是什麼。但我不認爲這是正確的。
SELECT CASE
WHEN A = '1' AND SendToA = '1' THEN 'true'
WHEN B = '1' AND SendToB = '1' THEN 'true'
WHEN C = '1' AND SendToC = '1' THEN 'true'
ELSE 'false'
END
FROM Table1
A,B,C,SendToA,SendToB,SendToC是在表中的字段和用於true
值和Success
= 1 SQLSERVER。 任何人都可以幫助我嗎?
多遠有你得到?你的桌子是什麼樣的? –
你有什麼試過的,你得到了什麼錯誤? – BugFinder
@BugFinder我試圖在SQL服務器中使用If..ELSE,我得到的只是語法錯誤。 [鏈接](https://docs.microsoft.com/en-us/sql/t-sql/language-elements/if-else-transact-sql) – xChaax