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