I am creating the following Sp, is it right to create a temp table inside the SP will it work.this is my first time using this logic.CREATE PROCEDURE [dbo].[Usp_GetCtrFundingSources] @contractid int ASDECLARE @ElementID IntDECLARE @CUR_TEMP CURSORSET @CUR_TEMP = CURSOR SCROLL FOR (select distinct(element_id) from tab_ccsnetelementcontracts where contractid=@contractid)CREATE TABLE #TEMP(efundid INT,fundid INT,fund_source nvarchar(100))OPEN @CUR_TEMPFETCH FIRST FROM @CUR_TEMP INTO @ElementIDWHILE @@FETCH_STATUS = 0BEGIN insert into #TEMP(efundid,fundid,fund_source) select efund.efund_id,efund.fundid, fndsrc.fund_source from Tab_ccsNetEfund efund inner join Tab_ccsNetFundSource fndsrc on efund.fundid = fndsrc.fundid where efund.element_id=@ElementID FETCH NEXT FROM @CUR_TEMP INTO @ElementID EndClose @CUR_TEMPDeallocate @CUR_TEMP insert into #TEMP(efundid,fundid,fund_source) select efund.efund_id,efund.fundid, fndsrc.fund_source from Tab_ccsNetEfund efund inner join Tab_ccsNetFundSource fndsrc on efund.fundid = fndsrc.fundid where efund.element_id=@ElementID select efundid,fundid,fund_source from #TEMPDrop table #TEMP
Thank you very much for the helpful info.