coperations07
asked on
Return Multiple Identical Records
Hello,
I need to return multiple records for each record in a table based on the numeric value of one of the columns. I have this working in a separate sproc (example below) , but it is using non-numeric values to determine number of rows. I'm looking for a more mathy way to use the quantity column to determine the number of rows to return, so I don't have to have a hundred union alls.
Sample data is attached. The confirmeddrops field is the one that determines how many duplicates of the row to return.
C--Users-dcastling-Desktop-Book1.xlsx
*MS SQL SERVER 2008 R2
I need to return multiple records for each record in a table based on the numeric value of one of the columns. I have this working in a separate sproc (example below) , but it is using non-numeric values to determine number of rows. I'm looking for a more mathy way to use the quantity column to determine the number of rows to return, so I don't have to have a hundred union alls.
Sample data is attached. The confirmeddrops field is the one that determines how many duplicates of the row to return.
C--Users-dcastling-Desktop-Book1.xlsx
--Return multiple rows based on breakpoint/level.
INSERT INTO @Results(program,wAgin,mrkNbr,brand,ofln,bp,oflnAG,oflnCA,oflnCR,oflnGB,oflnTT,oflnWM)
SELECT program,wAgin,mrkNbr,SUBSTRING(loc,3,2) Brand, SUBSTRING(fill,5,4) Ofln,bp,'','','','','',''
FROM tbl_lsu
CROSS APPLY (
SELECT 1 AS bp_repeater UNION ALL
SELECT 2 WHERE bp IN ( 'D', 'T', 'Q' ) UNION ALL
SELECT 3 WHERE bp IN ( 'T', 'Q' ) UNION ALL
SELECT 4 WHERE bp IN ( 'Q' )
) AS bp_repeater
WHERE SUBSTRING(loc,3,2) = @Brand
AND program = @Prog
AND progYear = @Year
AND Convert(int,SUBSTRING(fill,5,4)) BETWEEN @Ofln AND @LOfln
*MS SQL SERVER 2008 R2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It's for a Quality Control check application. Scan checks one by one with a timestamp on each check.
Thanks I'll give the tally a try.
Thanks I'll give the tally a try.
coperations07, do you still need help with this question?
Why?
The tally table suggestion above will certainly solve the specific question, but why are you needing this deliberate repetition?