STOCRIC
asked on
TSQL while loops and test data fom lookup tables
I would like to create some test data for a budget table.
I would like to look in the sales rep table and then create a bunch of data for that, then it should go to the next record in the rep table and create the same data but with the Rep filed populated with this second person etc. until the whole rep table is done.
Once I have understood that,I would like to amend it so that It looks in other tables to get other information as well as rep info.
fied names are
budget_dimension_group i.e. Cost_centre, rep
budget_dimension_item - this would be the rep name, or the cost centre which is stored in the small cost centre or rep table.
The output would look like this
I am not really whizzo programmer, I think there are nested while loop involved but what I can't seem to find is how to get values from other tables as the input parameters into the while loop.
apologies if this doesn't sound very clear, feel free to ask more questions.
Please help, I would be forever grateful.
I would like to look in the sales rep table and then create a bunch of data for that, then it should go to the next record in the rep table and create the same data but with the Rep filed populated with this second person etc. until the whole rep table is done.
Once I have understood that,I would like to amend it so that It looks in other tables to get other information as well as rep info.
fied names are
budget_dimension_group i.e. Cost_centre, rep
budget_dimension_item - this would be the rep name, or the cost centre which is stored in the small cost centre or rep table.
The output would look like this
I am not really whizzo programmer, I think there are nested while loop involved but what I can't seem to find is how to get values from other tables as the input parameters into the while loop.
apologies if this doesn't sound very clear, feel free to ask more questions.
Please help, I would be forever grateful.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks for the info, I'll take a look and let you know.
ASKER
so obvious, but a really elegant solution, thanks very much
1, budget look up table part:
When create the budget table, you can do it in an Excel file then load them into database.
It is an once-off job. I think Excel is the best way to go.
2, in report part:
In report, you return data from stored procedure through temp tables.
of course you can record your report data into a report table, if a report will take very long time to run.
What you should do is put a time-stamp on the report records.
In the stored procedure, you can based on the "budget_dimension_group","