SQLTeam.com | Weblogs | Forums

If on a view

sql2008

#1

Hi,
I have a script as below
IF Exists(
select a.tgl2,a.Dosen,a.nmdos,a.MK,a.nmk,a.drn,a.dosen,b.mk,b.prioritas from view_jadwalkuliah a
left join view_kurdosen b on a.mk=b.mk and a.dosen=b.dosen where a.drn >1
)
Begin
select a.tgl2,a.Dosen,a.nmdos,a.MK,a.nmk,a.drn,a.drn+1 as ndrn,b.dosen,b.nmdos,b.mk,b.prioritas from view_jadwalkuliah a
left join view_kurdosen b on a.mk=b.mk and a.drn+1=b.prioritas where a.drn >1
END

I need to put it into a view..but there's an error said " Incorrect syntax near IF " can anyone help me for the solution?

thx


#2

What do you want the VIEW to return if there is no EXIST match? A VIEW returns a recordset - it could return an empty recordset - but you will still get a recordset (whereas with your IF statement you will NOT get a recordset at all)

Perhaps you want a Stored Procedure? that can have IF (and NO recordset returned if EXISTS is false)


#3

if there were not exist the view will resulting the original data. So if it's possible with store procedure what will be the best script should I put?

thanks,

Joe