Forum guidelines
AuthorQuestion
Incorrect syntax near the keyword 'select'
Posted By anil john on 17 Dec 2012
Gtting h error:

Msg 156, Level 15, State 1, Procedure sp_DcPymentnsert, Line 16
Incorrect syntax near the keyword 'select'.
Msg 156, Level 15, State 1, Procedure sp_DcPymentnsert, Line 18
Incorrect syntax near the keyword 'select'.
Msg 156, Level 15, State 1, Procedure sp_DcPymentnsert, Line 20
Incorrect syntax near the keyword 'select'.

my pocedure

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        Anil K John
-- Create date: 1/12/2012
-- Description:    Daily collection Payment
-- =============================================
CREATE PROCEDURE sp_DcPymentnsert
    (
    @iChitId int,
    @iRegId int,
    @fPaidAmount float,
    @dPaidate datetime
    )
AS
BEGIN
declare @fInstmount float
set @fInstmount=select fInstmount from tblChitInstalments where iChitId=@iChitId and iInstNo=(select max(iInstNo) from tblDCPayment where ichitId=@iChitId)   
declare @dInstDate datetime
set @dInstDate=select dInstDate from tblChitInstalments where iChitId=@iChitId and iInstNo=(select max(iInstNo) from tblDCPayment where ichitId=@iChitId)
declare @Balance float
set @Balance=select fInstmount-fPaidAmount from tblDCPayment where iChitId=@iChitId and iRegId=@iRegId
INSERT INTO tblDCPayment(iChitd,iRegId,iInstNo,fInstAmount,dInstDate,fPaidAmount,fBalance,dPaidDate)
VALUES(@iChitId,@iRegId,'1',@fInstmount,@dInstDate,@fPaidAmount,@Balance,@dPaidate)
       
END
GO


AuthorReply
Re: Incorrect syntax near the keyword 'select'
Posted By anil john on 17 Dec 2012  
set @fInstmount=(select fInstmount from tblChitInstalments where iChitId=@iChitId and iInstNo=(select max(iInstNo) from tblDCPayment where ichitId=@iChitId))   
declare @dInstDate datetime
set @dInstDate=(select dInstDate from tblChitInstalments where iChitId=@iChitId and iInstNo=(select max(iInstNo) from tblDCPayment where ichitId=@iChitId))
declare @Balance float
set @Balance=(select fInstmount-fPaidAmount from tblDCPayment where iChitId=@iChitId and iRegId=@iRegId)

Re: Incorrect syntax near the keyword 'select'
Posted By venkata kumar on 17 Dec 2012  
hi
u need to give brakets
example :
declare @qty int
set @qty=(select qty from tablename)


u can execute the fallowing procedure.
CREATE PROCEDURE sp_DcPymentnsert
    (
    @iChitId int,
    @iRegId int,
    @fPaidAmount float,
    @dPaidate datetime
    )
AS
BEGIN
declare @fInstmount float
set @fInstmount=(select fInstmount from tblChitInstalments where iChitId=@iChitId and iInstNo=(select max(iInstNo) from tblDCPayment where ichitId=@iChitId))   
declare @dInstDate datetime
set @dInstDate=(select dInstDate from tblChitInstalments where iChitId=@iChitId and iInstNo=(select max(iInstNo) from tblDCPayment where ichitId=@iChitId))
declare @Balance float
set @Balance=(select fInstmount-fPaidAmount from tblDCPayment where iChitId=@iChitId and iRegId=@iRegId)
INSERT INTO tblDCPayment(iChitd,iRegId,iInstNo,fInstAmount,dInstDate,fPaidAmount,fBalance,dPaidDate)
VALUES(@iChitId,@iRegId,'1',@fInstmount,@dInstDate,@fPaidAmount,@Balance,@dPaidate


Thanks & Regards
Ravi Kumar

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.