Advanced WHERE clause in Stored Procedure for SQL Server 2005.
Posted on 2009-03-31
Im using SQL Server 2005 and have question. I have follow SP
CREATE PROCEDURE [dbo].[New_ForTest]
SELECT * FROM dbo.Events ORDER BY EventID
SELECT * FROM dbo.Events ORDER BY ModuleID,EventID
It is about this @TypeOrder. Is there other short way to produce same result ? SOmethink like:
SET @Order=" ORDER BY EventID"
SET @Order=" ORDER BY ModuleID,EventID"
SELECT * FROM dbo.Events + @Order
I need this because order type can be 5-6 ways and I do not want to have different SELECT FOR every of this order by , if I need to change this SQL I will need to do this in all 5-6 SQL which is foolishly ...