Return Rows as per Quantity of Columns Value In SQL

erikTsomik
erikTsomik used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jim HornSQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015

Commented:
>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.
Jim HornSQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015

Commented:
Also your query does not specify how t and n are related.  JOIN, LEFT JOIN, CROSS JOIN, ...
erikTsomikSystem Architect, CF programmer

Author

Commented:
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 ')'.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

erikTsomikSystem Architect, CF programmer

Author

Commented:
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
SQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015
Commented:
>i was  trying  to use this idea
You missed the comma after T
erikTsomikSystem Architect, CF programmer

Author

Commented:
Thank you. what a silly mistake

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial