What I am trying to do is create multiple rows from 1 record.. easily.
This is for a report. I can write repitive cursors but I just wondering if there is an easier way. For ex.
Say my select returns a set of records each with a field to tell me how many times I need to repeat that record. (simple example)
5 Tuesday
1 Wednesday
2 Sunday
I want the final select result to be for printing.
Tuesday
Tuesday
Tuesday
Tuesday
Tuesday
Wednesday
Sunday
Sunday
-----------------------------------------------------------------
Now, utopia would be to be able to do this in the 1st select.
Say I had a 3 entries in the table prior to the select with
count Data
5 Tuesday
1 Wednesday
2 Sunday
Could I dynamically (without a cursor), generate the 8 records?
I tried
1) SELECT TOP (select count from xxx) *
from Table.
2) Inner joining on the count of records.
3) Having clause with a select
And about 900 other gyrations to no avail. My actual SELECT gets the orig. data from mult. tables with 3 union queries. It is quite complex, as one of the fields will be a counter of the number of records. I am just trying to simplify it for this post.
The only option I see now is to run the orig. select with its unions and capture the counter in a temp file. (something like I have as the example)
Then writing a cursor and looping thru each record by the counter number of times and adding the records to the temp file.
Then selecting the temp file for the report. I am cringing to think how long this will take.
If anyone has ideas or needs more info., I am all ears.
Remember when... everything worked and there was a reason for it?
This is for a report. I can write repitive cursors but I just wondering if there is an easier way. For ex.
Say my select returns a set of records each with a field to tell me how many times I need to repeat that record. (simple example)
5 Tuesday
1 Wednesday
2 Sunday
I want the final select result to be for printing.
Tuesday
Tuesday
Tuesday
Tuesday
Tuesday
Wednesday
Sunday
Sunday
-----------------------------------------------------------------
Now, utopia would be to be able to do this in the 1st select.
Say I had a 3 entries in the table prior to the select with
count Data
5 Tuesday
1 Wednesday
2 Sunday
Could I dynamically (without a cursor), generate the 8 records?
I tried
1) SELECT TOP (select count from xxx) *
from Table.
2) Inner joining on the count of records.
3) Having clause with a select
And about 900 other gyrations to no avail. My actual SELECT gets the orig. data from mult. tables with 3 union queries. It is quite complex, as one of the fields will be a counter of the number of records. I am just trying to simplify it for this post.
The only option I see now is to run the orig. select with its unions and capture the counter in a temp file. (something like I have as the example)
Then writing a cursor and looping thru each record by the counter number of times and adding the records to the temp file.
Then selecting the temp file for the report. I am cringing to think how long this will take.
If anyone has ideas or needs more info., I am all ears.
Remember when... everything worked and there was a reason for it?