如果两者都为空,则返回两个日期或特定文本中的较低者

时间:2018-06-01 15:12:47

标签: sql-server date reporting-services case

我试图从两个字段中找到较低的日期。该字段也可以为NULL,因此选择非NULL或两者都为NULL然后' Some Error'

从此填充POdate(我将其与其他字段一起放入临时表中)

with open('Output.txt', 'r') as f:
    currentValues = set()

    for line in f.readline():
        currentValues.add(int(line))

    if idValue in currentValues:
        print("I found nothing interesting :(")
    else:
        send_message_to_slack(string)
        print("bingo, message sent!")

        # Saving the value retrieved to a text file for the next call
        with open("Output.txt", "a") as text_file:
            #print("{}".format(idValue), file=text_file)
            text_file.write("\n"+idValue)

time.sleep(100)

和WOdate这样(我把它和其他字段一起放在临时表中)

    (SELECT MIN(PD.ReceiptDate)
FROM Structure.Parts
INNER JOIN Purchase.PurchaseOrderDetails PD   ON pd.PartID = structure.Parts.PartID    
INNER JOIN Purchase.PurchaseOrders PO     
ON PD.PurchaseOrderNumber = PO.PurchaseOrderNumber 
WHERE Structure.Parts.Partnumber = sp.PartNumber AND (PO.PurchaseOrderStatusCode < 4) --4 Complete 5 --Cancelled       
AND (PD.ReceiptStatusID IN (1,2) )) AS POdate,

我的案例陈述在这里

(SELECT MIN(wt.CompletionDate)
FROM Structure.Parts
INNER JOIN Production.WorksOrder as wo     
ON  wo.PartID = Structure.Parts.PartID  
INNER JOIN Production.WorksOrderTransfers  wt ON wt.WorksOrderNumber = wo.WorksOrderNumber  
WHERE Structure.Parts.Partnumber = sp.PartNumber AND wt.WorksOrderStatusCode < 4      
AND (wt.BatchQuantity - ISNULL (wt.QuantityStored,0)) > 0 )
 AS WOdate,

非常感谢任何指针

1 个答案:

答案 0 :(得分:1)

这应涵盖所有可能的情况

CASE
WHEN POdate IS NULL AND WOdate IS NULL
    THEN 'No Planned Stock'
--If desired output for BOTH EQUAL case is 'No Planned Stock'
--replace the above WHEN with below one
--WHEN ISNULL(POdate, '99990101') = ISNULL(WOdate, '99990101')
    --THEN 'No Planned Stock'
WHEN ISNULL(POdate, '99990101') > ISNULL(WOdate, '99990101')
    THEN CAST (WOdate AS varchar (25)) 
WHEN ISNULL(POdate, '99990101') < ISNULL(WOdate, '99990101')
    THEN CAST (POdate AS varchar (25)) 
END AS StockDueIn