Reputation: 509
I have this query I am trying to trouble shoot, it is using a full outer join with some subqueries. But I am getting Null for some of the columns title TMS_ID
, I am trying to get these NULL TMS_IDs
to populate with the value of another column Employee_ID
. I am trying to get it to operate like
ISNULL(TMS_ID, Employee_ID) AS TMS_ID
Is this doable or is there another method I need to go about to accomplish this?
SELECT AC.REG_NR
,AC.DIS_NR
,AC.GEMSID
,AC.TMS_ID
,AC.EMP_NA
,AC.EMP_SEX_TYP_CD
,AC.EMP_EOC_GRP_TYP_CD
,AC.DIV_NR
,AC.CTR_NR
,AC.JOB_CLS_CD_DSC_TE
,AC.JOB_GRP_CD
,AC.Job_Function
,AC.Job_Group
,AC.Meeting_Readiness_Rating
,AC.Manager_Readiness_Rating
,CD.Employee_ID
,CD.Meeting_Readiness_Rating AS Expr1
,CD.Manager_Readiness_Rating AS Expr2
,CD.Meeting_End_Date
,CD.EmployeeFeedback
,CD.DevelopmentForEmployee1
,CD.DevelopmentForEmployee2
,CD.DevelopmentForEmployee3
,CD.DevelopmentForEmployee4
,CD.DevelopmentForEmployee5
,CD.Justification
,CD.Changed
,CD.Notes
Upvotes: 1
Views: 401
Reputation: 77876
Do it like
Case When TMS_ID is null then Employee_ID
else TMS_ID end AS Calculated_TMS_ID
(OR)
COALESCE(TMS_ID,Employee_ID)
In the case of coalesce
it will check if TMS_ID
is null then use first non-nullable
value; in which case it will use the value of Employee_ID
(OR)
ISNULL ( TMS_ID,Employee_ID )
But remember, Employee_ID
must of same type as TMS_ID
OR must be implicitly convertible to TMS_ID
Upvotes: 1