CREATE PROCEDURE udp_MULTI_SORT @FIELD1 VARCHAR(15), @FIELD2 VARCHAR(15)
AS
SELECT *
FROM RM00101
ORDER BY CASE
WHEN @FIELD1 = 'Col1' THEN Col1
WHEN @FIELD1 = 'Col2' THEN Col2
--- etc ----
END
,CASE
WHEN @FIELD2 = 'Col1' THEN Col1
WHEN @FIELD2 = 'Col2' THEN Col2
--- etc ----
END
// note: in above suggestion, you might need to add more "case statements" to accomodate for different data types
OR, the quick and dirty method
CREATE PROCEDURE udp_MULTI_SORT @FIELD1 VARCHAR(15), @FIELD2 VARCHAR(15)
AS
exec(SELECT * FROM RM00101 ORDER BY [' + @FIELD1 + '],[' + @FIELD2 +']')
|