Avatar of erikTsomik
erikTsomik
Flag 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

Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
erikTsomik

8/22/2022 - Mon
Jim Horn

>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 Horn

Also your query does not specify how t and n are related.  JOIN, LEFT JOIN, CROSS JOIN, ...
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 started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
erikTsomik

ASKER
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
Jim Horn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
erikTsomik

ASKER
Thank you. what a silly mistake