我試圖讓這個語句來工作,但它說我有錯誤的「INV.CaseQty = 1」SQL CASE WHEN語句
我想要得到它的邏輯:
when x = 1 then y = 1 else y
CASE WHEN INV.CaseUp = 1 then INV.CaseQty = 1 ELSE INV.CaseQty end
非常感謝大家的幫助
這是我從一個存儲過程
select C.CustomerNum, ISNULL(ST.ShiptoNum,'') Shipto, I.InvoiceNum,
DatePart(yyyy,I.InvoiceDate) DeliveryYear,
DatePart(qq,I.InvoiceDate) DeliveryQuarter,
DatePart(MM,I.InvoiceDate) DeliveryMonth,
DatePart(WW,I.InvoiceDate) DeliveryWeek,
CAST(I.InvoiceDate as Date) DeliveryDate, INV.InventoryNum,
IP.InventoryPackageNum, ISNULL(CaseQty, 0) QTYinEach,
ID.Description,ISNULL(IT.Description,'No Type') SubCategory,
CASE WHEN INV.CaseUp = 1 then INV.CaseQty = 1
ELSE INV.CaseQty
end
原TABL SELECT查詢Ë
Description CaseQty caseup
Royal 5" Red Stripe Plastic Sip Stirrer 1000 1
Ecoproducts Plant Starch Knife 1000 0
Ecoproducts Plant Starch Fork 1000 1
Ecoproducts Plant Starch Spoon 1000 0
我想從我的存儲過程的SELECT查詢能夠改變那些CaseUp = 1,CaseQty應該變爲1爲好。
你想達到什麼是它的select語句?發佈完整的查詢以獲得合適的答案 –
是的,我想在select語句中使用它,所以如果我要執行IF語句,我不能將它放在select語句中。我只能使用CASE。我如何解決這個問題? – kate
發佈您的選擇查詢以顯示您想要達到的效果或查詢後至少可以查看錶格數據和結果數據以瞭解您的要求 –