我想在不使用任何 if 语句的情况下重写此代码。
有可能这样做吗?
我如何使用案例或其他东西?
IF @BrandFilter = ''
BEGIN
SELECT * FROM
(
SELECT
ROW_NUMBER() OVER(ORDER BY
CASE WHEN @SortType = '1' THEN mt.Ad END ASC,
CASE WHEN @SortType = '2' THEN mt.Ad END DESC,
CASE WHEN @SortType = '3' THEN mt.Fiyat END ASC,
CASE WHEN @SortType = '4' THEN mt.Fiyat END DESC) AS RowNr, *
FROM @MainTable mt
WHERE mt.Fiyat > @MinPrice AND mt.Fiyat < @MaxPrice
) Result
WHERE RowNr > ((@PageNr-1) * 10) AND RowNr <= ((@PageNr) * 10)
END
ELSE
BEGIN
SELECT * FROM
(
SELECT
ROW_NUMBER() OVER(ORDER BY
CASE WHEN @SortType = '1' THEN mt.Ad END ASC,
CASE WHEN @SortType = '2' THEN mt.Ad END DESC,
CASE WHEN @SortType = '3' THEN mt.Fiyat END ASC,
CASE WHEN @SortType = '4' THEN mt.Fiyat END DESC) AS RowNr, *
FROM @MainTable mt
WHERE mt.Fiyat > @MinPrice AND mt.Fiyat < @MaxPrice
AND mt.MarkaId IN (SELECT bf.Data FROM dbo.Split(@BrandFilter, ',') bf)
) Result
WHERE RowNr > ((@PageNr-1) * 10) AND RowNr <= ((@PageNr) * 10)
END
这段代码是不同的,
AND mt.MarkaId IN (SELECT bf.Data FROM dbo.Split(@BrandFilter, ',') bf)
谢谢..