Sqlserver : Looping through temporary table

CREATE

TABLE #ActiveCustomer

(

 

RowID

intIDENTITY(1, 1),

formno

varchar(50),

adddel

varchar(50),

optionid

varchar(50)

)

DECLARE

@NumberRecords int, @RowCount

int

DECLARE

 

 

@form_no varchar(50),@previousform_no varchar(50),@add_del varchar(50), @option_id varchar(50

)

 

 

 

INSERT

INTO #ActiveCustomer(formno,adddel,optionid

)

 

select form_no, add_del, option_id from dbo.iws_kapiti_optionsorderby form_no

SET

@NumberRecords =

@@ROWCOUNT

 

SET

@RowCount =1

 

 

WHILE

@RowCount <= @NumberRecords

BEGIN

SELECT

@form_no = formno,@add_del = adddel,@option_id = optionid

FROM

#ActiveCustomer

WHERE

RowID = @RowCount

if

@add_del =

‘A’

 

begin

end

if

@add_del =

‘D’

 

begin

end

 

SET @RowCount = @RowCount + 1

END

 

DROP

TABLE#ActiveCustomer

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: