Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Optimizing Code(SP)

Author  Topic 

psfaro
Starting Member

49 Posts

Posted - 2011-04-08 : 04:15:56
Hi ,

Who can i optimize the folowing code in a SP:

I receive the parameter campo the can be :

VDB0, VDB1 , VDB2 ... always VD and (0 to 15)

i need to upgrade the Column that comes on the parameter, with especifing 15 times :

if @campo ='VDB0' ...


CODE:

if @campo='VDB0'

WHILE (1=1)
BEGIN
set @vc_c=substring(@conta,1,@nc_c)
if @nc_c >=1
UPDATE CCTPOC
set VDB0=VDB0 + @valor -- This is the column
where ano=@ano
and COD_CONTA=@vc_c
and TP_CONTA='G'

else
BREAK

set @nc_c= @nc_c - 1
END

-- and repeat so much times
if @campo='VDB1'


Regards

Pedro Faro

cns1202
Starting Member

7 Posts

Posted - 2011-04-08 : 05:26:30
Hi,

one solution could be going for a dynamic query whereby you can keep the whole thing same, but just instead of writing VDB0, write the variable name and then execute the query.
THen no condition required and you would be just fine.


Regards,
Chirag Shah
Go to Top of Page
   

- Advertisement -