Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL script for 120 updates

Status
Not open for further replies.

blom0344

Technical User
Mar 20, 2002
3,441
NL
I have to manually update a table 120 times which each statement having 5 variable parameters.

I there a way to put it into a script first, check the script and then run it?

Update example:

Code:
UPDATE    Slim4.Article
SET              demand[COLOR=red]0[/color] =
                          (SELECT     SLIM4.TEMP_ARTICLE_FISH_BRANCHE.D[COLOR=red]0[/color]
                            FROM          SLIM4.TEMP_ARTICLE_FISH_BRANCHE
                            WHERE      SLIM4.ARTICLE.CODE = SLIM4.TEMP_ARTICLE_FISH_BRANCHE.CODE AND SLIM4.TEMP_ARTICLE_FISH_BRANCHE.BRANCHE = 'F[COLOR=red]1[/color].')
WHERE     (warehouse = 'F[COLOR=red]1[/color].') AND (demand[COLOR=red]0[/color] IS NOT NULL)

Ties Blom
Information analyst
tbl@shimano-eu.com
 
Follow the procedure:

1- Declare variables
2- Set values
3- Use dyanmice Sql to make a sql statement
4- run it use exec (SQL)

For Example : I am assuming your red values as variable


Declare @var1 varchar(10)
Declare @var2 varchar(10)
Declare @var3 varchar(10)
Declare @var4 varchar(10)
Declare @str_SQL varchar(4000)


SET @var1 = '0'
SET @var2 = '0'
SET @var3 = '1.'
SET @var4 = '1.'


SET @str_SQL =
'UPDATE Slim4.Article
SET demand' + @var1 + ' =
(SELECT SLIM4.TEMP_ARTICLE_FISH_BRANCHE.D' + @var2 + '
FROM SLIM4.TEMP_ARTICLE_FISH_BRANCHE
WHERE SLIM4.ARTICLE.CODE = SLIM4.TEMP_ARTICLE_FISH_BRANCHE.CODE
AND SLIM4.TEMP_ARTICLE_FISH_BRANCHE.BRANCHE =' + '''F' + @var3 + ''')
WHERE (warehouse =' + '''F' + @var4 + ''') AND (demand' + @var1 + ' IS NOT NULL)'

Print @str_SQL

Exec (@str_SQL)


I don't know either you need to loop upto 120 times the same script so just add a while loop.

I hope it would work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top