sql - Simple If Statement in Stored Procedure -
i in no way dba , trying write perceive simple stored procedure. passing in parameters value of either 0 or 1, depending on parameter value want create temporary table , dump data out. basically, code follows;
alter procedure [dbo].[cfn_reportp360_calendar_mv_and_performance] @iuid int = null , @usertype varchar(1) = 'r' , @repid varchar(20) = null -- can vchplanid or vchhhplanid depends on @reporttype , @iworklistid int = 0 -- p360 group id , @reporttype varchar(1) = 'a' -- 'a' = acct acct, 'h' = household , @debug tinyint = 0 , @showdata tinyint = 1 -- 1 = show data, 0 = show year set nocount on if object_id('tempdb.dbo.#tempfinal') not null drop table dbo.#tempfinal if @showdata = 0 begin create table dbo.#tempfinal( year1perf text, year2perf text, year3perf text, year4perf text, year5perf text, year6perf text) insert dbo.#tempfinal select convert(varchar(8), getdate(), 1), '12/31/2012', '12/31/2011', '12/31/2010', '12/31/2009', '12/31/2008' end if @showdata = 1 begin create table dbo.#tempfinal( hhlevel_indicator text, ippsaccountid text, icfnaccountid text, vchaccountnumber text, vchaccountname text, vchplanid text, ihhid text, vchhhname text, year1perf text, year2perf text, year3perf text, year4perf text, year5perf text, year6perf text) insert dbo.#tempfinal select hhlevel_indicator,ippsaccountid,icfnaccountid,vchaccountnumber,vchaccountname,vchplanid,ihhid,vchhhname,year1perf,year2perf,year3perf,year4perf,year5perf,year6perf dbo.tbl_cfn_calendar_performance end select * dbo.#tempfinal if object_id('tempdb.dbo.#tempfinal') not null drop table dbo.#tempfinal i feel should good, everytime try run error of; msg 2714, level 16, state 1, procedure cfn_reportp360_calendar_mv_and_performance, line 47
there object named '#tempfinal' in database.
except on line 47 there no reference temp table @ all, may because comments ignored , have whole bunch of comments above code pasted, doesn't checking table , dropping @ end of sproc eliminate it? not sure go , great. thank in advance, nickg
at first place, here don't see need creating temp table, can directly run select statements , result. i'm not sure if performing operations on data in temp table, otherwise don't need them.
Comments
Post a Comment