I know I can do a UNION – but is there a better way to do this? We are using dynamic SQL and have it stored in tables with some the statements having an ORDER BY clause. I have to add a dynamic ‘All’ option, which is also stored in the database, to the top position to fill a drop-down in the app layer.
I know this is a wonky solution, but I’m trapped by the application’s current design. The other option is adding a bunch of code to the data model and app layer in addition to changing the stored procedure. If UNION is my only/best option, I can do that. I was just wondering if there was a better way on the database side.
Also, I don’t want a discussion on the merit of dynamic SQL strings stored in a database. It’s the way it is and it’s what I have to work with. Thanks all!
It sounds like your existing ORDER BY column(s) do not fulfil your current needs. Why don’t you add another column which explicitly details the Drop-Down control item placement, then ORDER BY that column in your Stored Procedure?
I’ll spare you the lecture on dynamic SQL. Just be careful with user input eh? 😉