UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Select Within A Select, SQL Server 2008 R2    
 
   
JV63
post Dec 1 2017, 01:09 PM
Post#1



Posts: 183
Joined: 16-August 12



Hi. I'm getting a "too many values" error message in the following query. I'm trying to pull a min of the ndc code from one table and then pull the other info from two tables where the ndc_code match between them.

I'm thinking it may just be my syntax because if I execute each select separately, the queries run.

Thanks

CODE
SELECT
LPAD(PRODUCT_CODE,7,0)||LPAD(PACK_CODE,3,0) AS CMF10,
BRAND_NAME,
GENERIC_NAME,

(SELECT
MIN (NDC_CODE),
LPAD(PRODUCT_CODE,7,0)||LPAD(PACK_CODE,3,0) AS CMF10
FROM NDCDBA.NDC_PACK_BRIDGE
group by product_code, pack_code)

FROM NDCDBA.NDC_PACK_BRIDGE A, NDCDBA.NDC_CODE B

WHERE A.NDC_CODE = B.NDC_CODE

Group By
PRODUCT_CODE,
PACK_CODE,
BRAND_NAME,
GENERIC_NAME

ORDER BY CMF10
Go to the top of the page
 
MadPiet
post Dec 1 2017, 02:38 PM
Post#2



Posts: 2,262
Joined: 27-February 09



Sounds like you need

<select statement 1>
UNION ALL
<select statement 2>

except make sure that the two statements are union-compatible.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    14th December 2017 - 01:08 AM