Solved

TSQL while loops and test data fom lookup tables

Posted on 2010-09-13
4
568 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 59

Accepted Solution

by:
Kevin Cross earned 500 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this article I will describe the Copy Database Wizard 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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now