Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I get the following results on a view.Job | Qty | Desc06-182 | 1 | B101106-324 | 2 | A110299-999 | 4 | AB839What I would like is the following.Job | Qty | Desc06-182 | 1 | B101106-324 | 1 | A110206-324 | 1 | A110299-999 | 1 | AB83999-999 | 1 | AB83999-999 | 1 | AB83999-999 | 1 | AB839
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2008-04-11 : 16:14:01
[code]DECLARE @Yak TABLE (Job VARCHAR(10), Qty INT, [Desc] VARCHAR(5))INSERT @YakSELECT '06-182', 1, 'B1011'UNION ALL SELECT '06-324', 2, 'A1102'UNION ALL SELECT '99-999', 4, 'AB839'SELECT A.Job, 1 AS Qty, A.[Desc]FROM @Yak AS AINNER JOIN (SELECT 1 AS Num UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS B ON A.Qty >= B.Num[/code]
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2008-04-11 : 16:18:43
For a more generic solution, try this
DECLARE @Sample TABLE (Job VARCHAR(6), Qty INT, [Desc] VARCHAR(5))INSERT @SampleSELECT '06-182', 1, 'B1011' UNION ALLSELECT '06-324', 2, 'A1102' UNION ALLSELECT '99-999', 4, 'AB839'SELECT s.Job, 1 AS Qty, s.[Desc]FROM @Sample AS sCROSS APPLY ( SELECT Number FROM master..spt_values WHERE [Type] = 'p' AND Number < s.Qty ) AS x