Greetings All!
I am working on a Stored Proc for a ColdFusion development team and am running into a few issues that I was wondering if anyone could help me with.
The SQL being passed to the server by the ColdFusion pages is currently being generated dynamically on the client side. The development team has recently determined that converting the SQL to a Stored Procs and running them on the server side would improve the performance of their app (and I agree). The issues I am running into is that their app is sending dynamic SQL based on the info that the user is requesting. This works fine on the application side but the coding standards implemented by our DBA group don't permit the use of dynamic SQL. So, I'm wondering if there is a SQL expert out there that may have some ideas on how I can get around this without writing billions of Stored Procs to handle each variation in the requested data.
Here are some examples of what I am up against:
(
@Var1 varchar(50),
@Var2 int
)
SELECT Tbl1.Col1, Tbl1.Col2, Tbl1.Col3
FROM Table1 AS Tbl1
<cfif ("local.Var1") = "Test"> -- ColdFusion IF Tag
INNER JOIN Table2 AS Tbl2 ON Tbl1.Col1 = Tbl2.Col1
</cfif> -- ColdFusion END IF Tag
WHERE Tbl1.Col3 = 'Nuts'
<cfif ("local.Var1") = "Test"> -- ColdFusion IF Tag
OR Tbl1.Col3 = 'Fruits'
</cfif>> -- ColdFusion END IF Tag
So, basically what this code is doing is writing a SQL statement to the server and, if Var1 = 'Test', it is adding 2 lines of SQL - 1 JOIN and 1 OR statement. Of course the real thing is quite a bit more complex than this but hopefully you get the idea. I come from the world of VB and I know you can add an IIF (immediate IF) statement to the selection criteria to dynamically change it at runtime. Does TSQL have an equivalent that could possibly be used here? Or maybe I simply need to take the blinders off and rethink my approach?
Thanks in advance for your thoughts!
Nathan C. Hoialmen
President
Encephalon Business Solutions, LLC
I am working on a Stored Proc for a ColdFusion development team and am running into a few issues that I was wondering if anyone could help me with.
The SQL being passed to the server by the ColdFusion pages is currently being generated dynamically on the client side. The development team has recently determined that converting the SQL to a Stored Procs and running them on the server side would improve the performance of their app (and I agree). The issues I am running into is that their app is sending dynamic SQL based on the info that the user is requesting. This works fine on the application side but the coding standards implemented by our DBA group don't permit the use of dynamic SQL. So, I'm wondering if there is a SQL expert out there that may have some ideas on how I can get around this without writing billions of Stored Procs to handle each variation in the requested data.
Here are some examples of what I am up against:
(
@Var1 varchar(50),
@Var2 int
)
SELECT Tbl1.Col1, Tbl1.Col2, Tbl1.Col3
FROM Table1 AS Tbl1
<cfif ("local.Var1") = "Test"> -- ColdFusion IF Tag
INNER JOIN Table2 AS Tbl2 ON Tbl1.Col1 = Tbl2.Col1
</cfif> -- ColdFusion END IF Tag
WHERE Tbl1.Col3 = 'Nuts'
<cfif ("local.Var1") = "Test"> -- ColdFusion IF Tag
OR Tbl1.Col3 = 'Fruits'
</cfif>> -- ColdFusion END IF Tag
So, basically what this code is doing is writing a SQL statement to the server and, if Var1 = 'Test', it is adding 2 lines of SQL - 1 JOIN and 1 OR statement. Of course the real thing is quite a bit more complex than this but hopefully you get the idea. I come from the world of VB and I know you can add an IIF (immediate IF) statement to the selection criteria to dynamically change it at runtime. Does TSQL have an equivalent that could possibly be used here? Or maybe I simply need to take the blinders off and rethink my approach?
Thanks in advance for your thoughts!
Nathan C. Hoialmen
President
Encephalon Business Solutions, LLC