Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

TSQL while loops and test data fom lookup tables

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 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