[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 944
  • Last Modified:

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,
0
jaws1021
Asked:
jaws1021
  • 2
1 Solution
 
crisco96Commented:
Just add a null to the end of your query


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,
null

0
 
jaws1021Author Commented:
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?
0
 
crisco96Commented:
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now