?
Solved

TSQL while loops and test data fom lookup tables

Posted on 2010-09-13
4
Medium Priority
?
575 Views
Last Modified: 2012-05-10
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

 example of completed table
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.

0
Comment
Question by:STOCRIC
  • 2
4 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 33663954
STOCRIC,

Greetings!

You may not need a nested while loop here is you are using the same data for each of the reps.  For example, say you are going to from budget table:

INPUT, 1, 2010, 700.00
...
OUTPUT, 6, 2010, 700.00

You could simply CROSS JOIN this to the data containing the individual reps and you will end up with all the rows of budget table repeated for each rep in the rep table(s).
0
 
LVL 4

Expert Comment

by:timexist
ID: 33668948
I think you can create a budget table with basic records.


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","budget_dimension_item" ... as parameters to return the budget values, and join them with the sales records.



0
 

Author Comment

by:STOCRIC
ID: 33669809
Many thanks for the info, I'll take a look and let you know.
0
 

Author Closing Comment

by:STOCRIC
ID: 33669854
so obvious, but a really elegant solution, thanks very much
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question