1
我有一個查詢(它的一部分),如下所示,當我的GridView加載了這個查詢時,那些沒有得到IssCount
和UsedCount
值的行將是空白的。如何爲這些記錄的這些列設置默認值0
?使用0作爲默認計數值
SELECT
CASE
WHEN @SortByTypeCode = 1 THEN ROW_NUMBER() OVER(ORDER BY vt.Code)
WHEN @SortByTypeName = 1 THEN ROW_NUMBER() OVER(ORDER BY vt.Name)
WHEN @SortByTypeIssued = 1 THEN ROW_NUMBER() OVER(ORDER BY count(X.IssCount))
WHEN @SortByTypeUsed = 1 THEN ROW_NUMBER() OVER(ORDER BY count(Y.UsedCount))
ELSE ROW_NUMBER() OVER(ORDER BY vt.AutoID)
END AS RowNum
,vt.AutoID
,vt.Code
,X.IssCount as Issued
,Y.UsedCount as Used
INTO #tmp_Results --Dont Change This
FROM VoucherType vt
LEFT JOIN (
SELECT VoucherType_AutoID,COUNT(VoucherNo) IssCount
FROM Voucher
WHERE VoidedBy IS NULL AND VoidedOn IS NULL
GROUP BY VoucherType_AutoID
) X ON vt.AutoID = X.VoucherType_AutoID
LEFT JOIN (
SELECT V.VoucherType_AutoID, COUNT(VUsed.AutoID) UsedCount
FROM voucherUsedLog VUsed
INNER JOIN Voucher V ON VUsed.Voucher_AutoID = V.AutoID
WHERE VUsed.VoidedBy IS NULL AND VUsed.VoidedOn IS NULL
GROUP BY V.VoucherType_AutoID
) Y
ON vt.AutoID = Y.VoucherType_AutoID