dharmer1975
Programmer
I've got a procedure that essentially creates and runs a select statement on a view that is specified via a single parameter. I'd now like to add multiple 'where conditions' to the generated statement in the procedure via using additional parameters. For example, here's my original procedure:
----------------------------------------
CREATE PROCEDURE FERPmonthly @selectedview Varchar (20)
as
declare @x as varchar(500)
set @x = 'select distinct((select cast(sum(Number_of_Responses)as float) from ' + @selectedview + ') / (select cast(count(distinct(imc_trackingnumber))as float) from ' + @selectedview + ')) as "# of Responses to Resolution"
from '+ @selectedview
execute( @x )
-----------------------------------------
This essentially generates the following statement when executed as follows 'execute harmerd.FERPmonthly "harmerd.mar01"':
select distinct((select cast(sum(Number_of_Responses)as float) from harmerd.mar01) / (select cast(count(distinct(imc_trackingnumber))as float) from harmerd.mar01)) as '# of Responses to Resolution'
from harmerd.mar01
--------------------------------------
Now I'd like the procedure to be able to generate a statement like this (same statement but with a where condition):
select distinct((select cast(sum(Number_of_Responses)as float) from harmerd.mar01) / (select cast(count(distinct(imc_trackingnumber))as float) from harmerd.mar01)) as '# of Responses to Resolution'
from harmerd.mar01
where exists ( select *
from harmerd.mar01
where pool like 'CL%')
-------------------------------------
Can anyone help me modify this procedure to accept one or more where conditions?
I'd like to have a procedure that can easily build a dynamic query based on the parameters I provide. These parameters are being scraped from and html page and posted to a java servlet that in turn executes a callable statement and returns the results of the query. Any assistance would be greatly appreciated as I've been spinning my wheels for a couple weeks now. Thanks,
Dan
----------------------------------------
CREATE PROCEDURE FERPmonthly @selectedview Varchar (20)
as
declare @x as varchar(500)
set @x = 'select distinct((select cast(sum(Number_of_Responses)as float) from ' + @selectedview + ') / (select cast(count(distinct(imc_trackingnumber))as float) from ' + @selectedview + ')) as "# of Responses to Resolution"
from '+ @selectedview
execute( @x )
-----------------------------------------
This essentially generates the following statement when executed as follows 'execute harmerd.FERPmonthly "harmerd.mar01"':
select distinct((select cast(sum(Number_of_Responses)as float) from harmerd.mar01) / (select cast(count(distinct(imc_trackingnumber))as float) from harmerd.mar01)) as '# of Responses to Resolution'
from harmerd.mar01
--------------------------------------
Now I'd like the procedure to be able to generate a statement like this (same statement but with a where condition):
select distinct((select cast(sum(Number_of_Responses)as float) from harmerd.mar01) / (select cast(count(distinct(imc_trackingnumber))as float) from harmerd.mar01)) as '# of Responses to Resolution'
from harmerd.mar01
where exists ( select *
from harmerd.mar01
where pool like 'CL%')
-------------------------------------
Can anyone help me modify this procedure to accept one or more where conditions?
I'd like to have a procedure that can easily build a dynamic query based on the parameters I provide. These parameters are being scraped from and html page and posted to a java servlet that in turn executes a callable statement and returns the results of the query. Any assistance would be greatly appreciated as I've been spinning my wheels for a couple weeks now. Thanks,
Dan