sql - Using a temp table to insert in stored procedure -
i have view trying declare temporary table in sql. i'm declaring it, getting error "must declare scalar variable @temp". i'm not sure why error occurring. below code stored procedure. end goal able use temp table's values on insert within stored procedure.
use [database] go set ansi_nulls off go set quoted_identifier off go alter procedure [dbo].[procinsertdrivetimeclaimcomponents] declare @iterator int declare @rowcount int declare @temp table ( rowiterator int, intclaimnum int, chrstscode varchar(50), chrcontnum varchar(5), chrcvgcode varchar(5), intcontcode int, chrcontsfx varchar(5), chrdlrnum varchar(5), chrpgmcode varchar(15), chrversion varchar(15), chrcvgtype varchar(15), chrronum varchar(15), dtmrodate datetime, intchecknum int ); set @iterator = 1 set @rowcount = (select count(*) viewdrivetimecontracts) while ( @iterator <= @rowcount ) insert @temp (rowiterator, intclaimnum, chrstscode, chrcontnum, chrcvgcode, intcontcode, chrcontsfx, chrdlrnum, chrpgmcode, chrversion, chrcvgtype, chrronum, dtmrodate, intchecknum) select * viewdrivetimeclaimrows rowiterator = @iterator begin insert tblclaimcomponents values ('cr', @temp.intclaimnum, '999999', 'description', @temp.chrcvgcode, @temp.intcontcode, @temp.chrcontnum, @temp.chrcontsfx, @temp.chrdlrnum, @temp.chrpgmcode, @temp.chrversion, @temp.chrcvgtype, 'complaint', @temp.chrronum, @temp.dtmrodate, 'a', 0, 0, 0, 'n', 0, 0, 0, 1, 'y', 0, '', '', '', 0, 0, 'n', 'n', 0, 'zingo', '01/01/2014', 'zingo', '01/01/2014', 'pd', 1, null, null, 0, '90444444', null, null, null, null, 0, 0, 0, 0, 0, 0, 0, 0, null, '01/01/2014', 'zingo', 'comment', '') set @iterator = @iterator + 1 end
@temp
table variable, if using columns variable, need put variable in from
clause. therefore, last insert statement should this:
insert tblclaimcomponents values select 'cr', intclaimnum, '999999', 'description', chrcvgcode .... --other values here @temp
Comments
Post a Comment