Link to home
Start Free TrialLog in
Avatar of erikTsomik
erikTsomikFlag for United States of America

asked on

Return Rows as per Quantity of Columns Value In SQL

I need to return as many rows as a qty column is telling me, but getting an error message
 	SELECT T.* 
 	FROM 
 	
 	(
 		SELECT O.orderKey,U.lastname,U.firstname,LIP.qty
    	FROM orders O
    	inner join lineItems LI on LI.orderKey = O.orderKey
    	inner join lineitems_product LIP on LIP.lineitemKey = LI.lineitemKey 
    	inner join users U on U.userKey = O.userKey	
    	WHERE O.void <> 'Y' 
    	and LI.productID = 'GC'
    )T
    (SELECT number
    FROM master..spt_values 
    WHERE Type = 'P') as  n
    
WHERE t.qty > n.number

Open in new window

Avatar of Jim Horn
Jim Horn
Flag of United States of America image

>but getting an error message
An excellent idea would be to tell us what that error message is, especially if you can double-click on it, watch the cursor jump to the offending line, and also tell us what that line is.
Also your query does not specify how t and n are related.  JOIN, LEFT JOIN, CROSS JOIN, ...
Avatar of erikTsomik

ASKER

Msg 156, Level 15, State 1, Line 13
Incorrect syntax near the keyword 'SELECT'.
Msg 102, Level 15, State 1, Line 15
Incorrect syntax near ')'.
i was  trying  to use this idea from the page which is what I need
http://stackoverflow.com/questions/25013503/return-rows-as-per-quantity-of-columns-value-in-sql
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you. what a silly mistake