|
|
Question : 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,
|
Answer : union
|
|
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
|
|
|
|
|