Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Dave writes "Let me start off by saying, I know this is not correct syntax, etc., it is just to graphically illustrate my question.
Is it possible (and how do you do it) to implement some type of generic stored procedure that would "function" as the code below shows (assuming it didn't violate syntax, etc):
CREATE PROCEDURE [spBuildSelectBox] @SelectBoxValue int, @SelectBoxText varchar(20), @TableName varchar(20), @OrderByItem varchar(20), @SortDir char(4) = 'ASC' AS SELECT '' FROM @TableName ORDER BY @SelectBoxText + ' ' + @SortDir
Basically, I'm searching for a way to create a "generic" stored procedure that I can use to populate the option attributes of an HTML select box. I want to be able to pass-in the value, text, table name, the field to order by, and the sort direction, all dynamically so I can reuse it. Is there some variation of this that would work? Any ideas are appreciated...