I am converting mysql query to sql query I have the below query, when i run this query in sql server it says
Error 156: Incorrect syntax near the keyword 'as'.
Can anyone please help why i am getting this error ?
Mysql Query(This is working fine in mysql):
UPDATE tb_Episode as e left JOIN tb_Payer as p ON (e.CustID = p.company_id) AND (e.PayorType = p.payor_type)
left JOIN tb_HHPPS as h ON e.HHPPS = h.HHPPS
SET
e.PayerType = If(p.payer_type=1,"Ep","NonEp"),
e.LUPAAlert = If((p.payer_type)<>"1",0,If(EpEnd<=Now(),0,If(TotVisits<5,1,0))),
e.LUPADays = If((If((p.payer_type)<>"1",0,If(EpEnd<=Now(),0,If(TotVisits<5,1,0))))=0,0,EpEnd-Now()),
e.FinalAlert = If((p.payer_type)<>"1",0,If(abs(DATEDIFF(Now(),EpEnd))>1,0,1)),
e.FinalDays = If((If((p.payer_type)<>"1",0,If(abs(DATEDIFF(Now(),EpEnd))>1,0,1)))=1,abs(DATEDIFF(Now(),EpEnd)),0),
e.RAPAlert = If(p.payer_type="1",If(abs(DATEDIFF(Now(),EpStart))>0,1,0),0),
e.RAPDays = If((If(p.payer_type="1",If(abs(DATEDIFF(Now(),EpStart))>0,1,0),0))=1,abs(DATEDIFF(Now(),EpStart)),0)
where e.billed_flag = "0"
SQLQuery (Getting error):
UPDATE tb_Episode as e left JOIN tb_Payer as p ON (e.CustID = p.company_id) AND (e.PayorType = p.payor_type)
left JOIN tb_HHPPS as h ON e.HHPPS = h.HHPPS
SET
e.PayerType = IIF(p.payer_type=1,'Ep','NonEp'),
e.LUPAAlert = IIF((p.payer_type)<>"1",0,IIF(EpEnd<=getdate(),0,IIF(TotVisits<5,1,0))),
e.LUPADays = IIF((IIF((p.payer_type)<>"1",0,IIF(EpEnd<=getdate(),0,IIF(TotVisits<5,1,0))))=0,0,EpEnd-getdate()),
e.FinalAlert = IIF((p.payer_type)<>"1",0,IIF(abs(DATEDIFF(millisecond,getdate(),EpEnd))>1,0,1)),
e.FinalDays = IIF((IIF((p.payer_type)<>"1",0,IIF(abs(DATEDIFF(millisecond,getdate(),EpEnd))>1,0,1)))=1,abs(DATEDIFF(millisecond,getdate(),EpEnd)),0),
e.RAPAlert = IIF(p.payer_type="1",IIF(abs(DATEDIFF(millisecond,getdate(),EpStart))>0,1,0),0),
e.RAPDays = IIF((IIF(p.payer_type="1",IIF(abs(DATEDIFF(millisecond,getdate(),EpStart))>0,1,0),0))=1,abs(DATEDIFF(millisecond,getdate(),EpStart)),0)
where e.billed_flag = '0'
(p.payer_type)<>"1", ispayer_typea number or a character datatype? Under the hood, there is a difference between'1'and1. Also,"<>'.UPDATEwithJOIN? That's probably the first thing you should do before posting here. Clearly you syntax is wrong.