I am making a vb.net project using SQL-SERVER at back end. Since SQL queries are lengthy i have to use STORED-PROCEDURE..
Following condition have to be tested in T-SQL. But my program frequently gives error ''INCORRECT SYNTAX NEAR BEGIN''
How can nested loop be used to execute following condition without error..
if @commissiontypee!=@commissiontypee1 or @commissionamountt!=@commissionamountt1 ( begin if exists (select debit from tblledger where passportnumber=@passportnumberr and (typenumber=2 or typenumber=3) ( begin update tblledger set debit=@commissionamountt, typenumber=@typenumberr where ( passportnumber=@passportnumberr and (TypeNumber='2' or TypeNumber='3')) set @initialdate= (select top(1) datetimer from tblledger where passportnumber=@passportnumberr and (typenumber=2 or typenumber=3)) set @datedifferences=datediff(day,@initialdate,getdate()) if @commissiontypee!=@commissiontypee1 ( begin insert into tbllogfiles (OnDate,What,OfPassportnumber,ToValue,ChangedFrom,aftertime)values(getdate(),'Commission and ""COMMISSION-TYPE"" changed',@passportnumberr,@commissionamountt,commissionamount,@datedifferences) end else begin insert into tbllogfiles (OnDate,What,OfPassportnumber,ToValue,ChangedFrom,aftertime)values(getdate(),'Commission changed',@passportnumberr,@commissionamountt,commissionamount,@datedifferences) end ) ) else ( begin if @commissiontype=0 --condition insert into tblledger (passportnumber,datetimer, typenumber,debit) values (@passportnumberr,getdate(),2,@commissionamountt) else --condition insert into tblledger (passportnumber,datetimer, typenumber,debit) values (@passportnumberr,getdate(),2,@commissionamountt) end ) end )
Regards
Saurav Gautam