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 2000 Forums
 Transact-SQL (2000)
 While Loop and Replace Help!!!

Author  Topic 

Concatch
Starting Member

4 Posts

Posted - 2011-05-26 : 02:45:41
I have a table called UpdatedFigures with the following headings: ProductType, Month13, Month14, Month15.......Month24. Under each month there are numeric values and under Product type there is a row for ProductAlpha, ProductBeta and ProductGama. Each Row is populated with eh numeric values from the months.

I have a separate table called ModelObject with a single column called Script.

In the script column I have
with_cell_ProductAlpha_TimePeriod.###.SetValue$$$
with_cell_ProductBeta_TimePeriod.###.SetValue$$$
with_cell_ProductGama_TimePeriod.###.SetValue$$$

I need to do a while loop that will will replace the ### with Month13 through to Month 24 and replace the $$$ with the corresponding values for the Months.

The scripts for ProductAlpha, ProductBeta and ProductGama will have 12 iterations each.

This is the basic concept I will need to apply it on a much larger scale.

Thanx in advance!!!

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-26 : 04:39:36
Why do you need a loop?

Do you want
with_cell_ProductBeta_TimePeriod.###.SetValue$$$
to change to
with_cell_ProductBeta_TimePeriod.Month13.SetValue$$$

Not sure what you want the $$$ to change to - is there a single row in your UpdatedFigures and you want the Month13 figure?

You will need a lookup table to map the greek letters to numbers - but if you are creating that - which will have 24 entries - you might as well manually update the script itself which I guess will also have 24 entries. That is unless there is some way of mapping the text to the month number already.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Concatch
Starting Member

4 Posts

Posted - 2011-05-26 : 05:15:47
I need a loop because what I want eventually is

with_cell_ProductAlpha_TimePeriod.Month13.SetValue 2525
with_cell_ProductAlpha_TimePeriod.Month14.SetValue 473643
with_cell_ProductAlpha_TimePeriod.Month15.SetValue $$$
"
"
"
with_cell_ProductAlpha_TimePeriod.Month24.SetValue 7347338

with_cell_ProductBeta_TimePeriod.Month13.SetValue$$$
with_cell_ProductBeta_TimePeriod.Month14.SetValue$$$
with_cell_ProductBeta_TimePeriod.Month15.SetValue$$$
"
"
"
with_cell_ProductBeta_TimePeriod.Month24.SetValue$$$

The $$$ will change to numeric values from the Updated figures table which looks like this:

Product Type Month13 / Month14/...Month17/..............Month24
ProductAlpha 2525 / 473643 /...some value/............7347338
ProductBeta 4534 / 623632 /...some value/...........38628638
ProductGama 6583 /834773 /...some value/...........84723236

This is a very simplified model. My actual Updated figures table contains over 2000 Product Types.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-26 : 07:17:57
Do you need to do an update or can you populate the ModelObject table from UpdatedFigures?
The way you describe this it sounds like the data isn't fixed.

The only way from your description is to Use the
with_cell_ProductAlpha_TimePeriod
to get the row from UpdatedFigures

But if the script is always

with_cell_<xxxxxx>_TimePeriod.<ccccc>.SetValue <$$$>
And you want entries for all rows in UpdatedFigures
then it's probably easier to generate from scratch.




==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -