Hello,Is any difference between this two procedure on performance ?Regards,sasan.CREATE PROC pr_TableData @table sysname , @clause nvarchar(3000)=null ASBEGIN SET NOCOUNT ON DECLARE @IdError int DECLARE @sql nvarchar(4000) IF @clause IS NULL BEGIN SELECT @sql = 'SELECT * FROM [' + @table + ']' + ' SELECT @IdError = @@error' EXEC sp_executesql @sql, N'@table sysname, @IdError int output', @table, @IdError output END ELSE BEGIN DECLARE @sub nvarchar(4000) SELECT @clause = replace(@clause, '"', '''') SELECT @sub = ' WHERE (' + @clause + ')' SELECT @sql = 'SELECT * FROM [' + @table + '] WHERE (' + @clause + ')' + ' SELECT @IdError = @@error' EXEC sp_executesql @sql, N'@table sysname, @clause nvarchar(3000), @IdError int output', @table, @clause, @IdError END RETURN @IdErrorEND
CREATE PROC pr_MyTableData @clause nvarchar(3000)=null ASBEGIN SET NOCOUNT ON DECLARE @IdError int DECLARE @sql nvarchar(4000) IF @clause IS NULL BEGIN SELECT @sql = 'SELECT * FROM tbl_my_data' + ' SELECT @IdError = @@error' EXEC sp_executesql @sql, N'@IdError int output', @IdError output END ELSE BEGIN DECLARE @sub nvarchar(4000) SELECT @clause = replace(@clause, '"', '''') SELECT @sub = ' WHERE (' + @clause + ')' SELECT @sql = 'SELECT * FROM tbl_my_data WHERE (' + @clause + ')' + ' SELECT @IdError = @@error' EXEC sp_executesql @sql, N'@clause nvarchar(3000), @IdError int output', @clause, @IdError END RETURN @IdErrorEND