假設我有序列號,測試名稱和其他幾個欄目,我想寫一個條件,如果TESTNAME is null
特定序列號,然後設置TESTNAME
空白否則執行內部聯接如果MSSQL else條件
SELECT
(A.PTNUMBER + '-' +A.SL_NO) AS ENUMBER,
D.ENGINEER AS REQ, D.DATETIME as "DATE",
(select Value
from DROPDOWN
where B.TEST_NAME=CONVERT(VARCHAR,DropdownID)) TESTNAME,
TABLE_NAME AS TABLETD
FROM INSPECTION D
INNER JOIN TABLEA A ON D.ENGID = CONVERT(VARCHAR,A.EN_ID)
INNER JOIN TABLEB B ON B.ENGID = CONVERT(VARCHAR,A.EN_ID)
INNER JOIN TABLEC C ON C.ENGID = CONVERT(VARCHAR,A.EN_ID)
結帳的情況下的關鍵字(https://docs.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql)向我們展示你到目前爲止所擁有的。我們不介意讀者:) – Jeremy
下一次,從查詢開始。它會阻止無法捕捉問題範圍或正確解決問題的答案。假設性問題不是[最小,完整或可驗證示例](https://stackoverflow.com/help/mcve)。爲了改進您的答案,[請查看此主題](https://stackoverflow.com/help/how-to-ask)幷包含測試數據[如此處所述](https://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum /)以及預期結果。乾杯 – scsimon