更新的问题:
ALTER PROC Proc_Test
(
@GrpBy as varchar(20)
)
AS
Declare @TableTax table(
Taxid int,
TaxRange nvarchar(20),
MinLimit int,
MaxLimit int
)
SELECT t1.*
FROM
(
SELECT
GroupBy = CASE @GrpBy
WHEN 'JobGrade' THEN Employee.Grade
WHEN 'Tax Slab' THEN tblTax.TaxRange
END, (20 more calculated columns)
FROM @TableTax AS tblTax, Employee
LEFT JOIN Grade on Grade.Grade = Employee.Grade
WHERE
Employee.Salary between tblTax.MinLimit and tblTax.Maxlimit
GROUP BY
CASE @GrpBy
WHEN 'JobGrade' THEN Employee.Grade
WHEN 'Tax Slab' THEN tblTax.TaxRange
END
) AS t1
ORDER BY GroupBy
我想按 TaxId 订购结果。此 order by 仅适用于在前端选择 Tax Slab 的情况。