Link to home
Start Free TrialLog in
Avatar of jaws1021
jaws1021

asked on

union

I added m.description to sp , where do I need to put something that my union wouldn't complain about All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.


alter procedure [dbo].[Getfinding]
(
      @iMedReviewID int,
        @iReview_num int      
)
as

SELECT
SortOrder as rank,
'Y' SELECTED,  
'Y' SELECTED_finding,  

f.finding_ID,  
f.ERR_CODE_ID,  
ERR_CODE.[DESC],  
f.TYPE,  
f.REVIEW_ID,  
f.REVIEW_NUM,  
f.ERR_AMT,  
f.BILLED_CODES_UNITS,
f.OVER_UNDER,  
f.POLICY_REF,
f.CORRECT_CODES_UNITS,
ERR_CODE.CODE,
ERR_CODE.SORTORDER,
m.description

FROM finding f
inner JOIN ERR_CODE ON
(
      f.ERR_CODE_ID = ERR_CODE.ERR_CODE_ID
)
inner Join med_qualifier m on
(
cast(CAST(f.POLICY_REF as VARCHAR(10)) As int) = m.Med_Qualifier_id
)
WHERE f.REVIEW_ID = @iMedReviewID
AND f.TYPE = 'M'
AND f.REVIEW_NUM = @iReview_num

UNION ALL

SELECT
SortOrder as rank,
'N' SELECTED,  
'N' SELECTED_finding,  

NULL,  
ERR_CODE.ERR_CODE_ID,  
ERR_CODE.[DESC],  
ERR_CODE.TYPE,  
@iMedReviewID,  
@iReview_num,  
null,  
null,
null,  
null,
null,
ERR_CODE.CODE,
ERR_CODE.SORTORDER,
ASKER CERTIFIED SOLUTION
Avatar of crisco96
crisco96
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
Avatar of jaws1021
jaws1021

ASKER

okay, I did that too, I wanted to make sure about that, have a question though, why we are adding null instead saying m.description on the end where we put null? Try to understand about null doing what?
You can add whatever you want to be in that last field that's returned in the result set.  If in your second query there's some field that matches up with the field m.description in your first query then add that field instead of null.