desiredforsome
asked on
SQL If NUll on Unpivot
So wondering if this sql code can have a statemet put in it that will do the following.
It runs the query as printed below but it checks to see if a specific feild is null.
So for instance this query currently does not have the field [appraisefinal]. I want it to while running this query do some if statements and say if appraisefinal is null then insert [appraisal ordered] into the item of outlookreport.dbo.calendar .
It runs the query as printed below but it checks to see if a specific feild is null.
So for instance this query currently does not have the field [appraisefinal]. I want it to while running this query do some if statements and say if appraisefinal is null then insert [appraisal ordered] into the item of outlookreport.dbo.calendar
;WITH MyCTE AS
(
SELECT *
FROM (
SELECT *
FROM emdb.dbo.calendarview
)p
UNPIVOT
(
EventDate FOR DateDescription in ([Appraisal Ordered],[Closing Date],[Application Signed],[Appraisal Recieved] ,[Approval To Close],[Insurance Ordered],[Title Ordered])
) as unpvt
)
insert into outlookreport.dbo.calendar (eventdate,item,xrefid)
SELECT
M.EventDate,
M.DateDescription,
T.xrefid
FROM emdb.dbo.calendarview T
JOIN MyCTE M
ON T.xrefid = M.xrefid
WHERE NOT EXISTS(SELECT 1 FROM outlookreport.dbo.calendar WHERE eventdate = M.EventDate AND xrefid = T.xrefid);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.