On my asp.net project, there are instances where a server side filter function in C# is building an SQL WHERE clause, then passing it into an SQL stored procedure for example,
Filter produces a string variable with a value like “WHERE Qty < 5 AND Price > 10”.
The relevant part of the Stored Procedure is like:
Exec (‘
Select Name, Location
From Users
+ ‘@passedInWhereClause’
‘)
As you can see, we have to do an EXEC command on a string built with the passed in variable containing the where clause that was generated by C# code on the server side.
I would really like a way to eliminate the EXEC and make the SQL code look more professional, instead of a giant string wrapped with an EXEC. Is there any better way to do this?