2007년 5월 16일 수요일

되도록이면 한방쿼리 하지만 그게 더 귀찬을때가..(처리를 구현하는 사고 방식의 전환)

declare @tmptable table(
A int identity(1,1) not null,
B int not null,
C int not null
)

insert @tmptable (B,C) select B,C  from CONTENT_TABLE
where B in(1,5,10,50,100,200,300,400,500,600,700,800,900,1000) and X = 'WHAT'

declare @i int,@maxcounter int
declare @B  int
declare @C int
set @i = 0;

select @maxcounter = count(*) from @tmptable
while @i < @maxcounter

begin
set @i = @i+1
select @B = B,@C = C  from @tmptable where A =@i

if(@C =1)
  exec PROCEDURE @B,30000
else if(@C = 5 OR @C = 10 OR @C = 50)
  exec PROCEDURE @B,10000
else if(@C = 100 OR @C = 200 OR @C = 300 OR @C = 400)
  exec PROCEDURE @B,7500
else if(@C = 500 OR @C = 600 OR @C = 700 OR @C = 800 OR @C = 900 OR @C = 1000 )
  exec PROCEDURE @B,5000
else
  select 'ERROR'
end

댓글 없음: