Using a Stored Procedure parameter within the From of another -
i have stored procedure outputs totals eform table. want use stored procedure pull out data other eform tables , want replace eform table name in clause parameter. i've read other questions, can't find 1 helps using parameter in from. code stored procedure looks -
if object_id ('sp_selecteformmonthlytotals') not null drop procedure sp_selecteformmonthlytotals go create procedure sp_selecteformmonthlytotals @eformname varchar (200) = '' create table #temp (eformname varchar (200)) insert #temp exec sp_updateeform @eformname select .... @eformname t1 inner join flods_case_enquiry_f00 t2 on t1.eform_case_enquiry_id = t2.case_enquiry_id t2.created_dt >= '2012-04-02' group month(t2.created_dt), year(t2.created_dt)) t3 order year, month_number drop table #temp
this latest attempt of many , includes second stored procedure called sp_updateeform -
if object_id ('sp_updateeform') not null drop procedure sp_updateeform go create procedure sp_updateeform @eformname varchar (200) = '' update francis set eformname = @eformname
i created francis table hold eformname. can see need set value of @eformname before sp_selecteformmonthlytotals can complete, can't seem find way of doing this.
thanks.
frank
you need use dynamic query this;
create procedure sp_selecteformmonthlytotals @eformname varchar (200) = '' create table #temp (eformname varchar (200)) insert #temp exec sp_updateeform @eformname declare @ssql varchar(2000), @datecreated varchar(10) set @datecreated = '2012-04-02' set @ssql = 'select .... ' set @ssql = @ssql + ' ' + @eformname + ' t1 inner join flods_case_enquiry_f00 t2 on t1.eform_case_enquiry_id = t2.case_enquiry_id ' set @ssql = @ssql + ' t2.created_dt >= '' + @datecreated + ''' set @ssql = @ssql + ' group month(t2.created_dt), year(t2.created_dt)) t3' set @ssql = @ssql + ' order year, month_number' exec @ssql drop table #temp
Comments
Post a Comment