Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone ,
I have a CircleId like Gujarat,maharashtra,uttarPradesh ..and So on
I want to perform three condition:
1 st Condition :If i found the same record in database,it should not save the Record.
2 nd Condition: New Record should get Add.
3 rd Condition:if i found more than 4 record for the same CircleId it should not allow to save.
But I am getting a Error as follows .
Msg 156, Level 15, State 1, Procedure K2_CHECKENTRYINFILELOG, Line 50
Incorrect syntax near the keyword 'begin'.
Msg 156, Level 15, State 1, Procedure K2_CHECKENTRYINFILELOG, Line 56
Incorrect syntax near the keyword 'else'.

Stored Procedure is As follows:
ALTER PROCEDURE [dbo].[K2_CHECKENTRYINFILELOG] 
@FILENAME VARCHAR(150),
@FILEPATH VARCHAR(MAX),
@FILETYPE int,
@FILEDATE datetime,
@CIRCLEID INT,
@TOTALROWS int,
@SUCCESSCOUNT int,
@FAILURECOUNT int,
@PROCESSED bit,
@ERROR varchar(MAX),
@VENDORID int,
@CREATEDBY INT = 1,
@CREATEDON DATETIME,
@DELETED BIT=0,
@FILELOGID bigINT

AS	
BEGIN	
	IF NOT EXISTS (
select count(CIRCLEID) from K2FILELOG where FILEPATH = @FILEPATH and
                                              [FILENAME] = @FILENAME and
                                              FILETYPE = @FILETYPE and
                                              FILEDATE = @FILEDATE and
                                              CIRCLEID = @CIRCLEID and
                                              TOTALROWS = @TOTALROWS and
                                              SUCCESSCOUNT = @SUCCESSCOUNT and
                                              FAILURECOUNT = @FAILURECOUNT and
                                              PROCESSED = @PROCESSED and
                                              ERROR = @ERROR and
                                              VENDORID = @VENDORID and
                                              CREATEDBY = @CREATEDBY and
                                              CREATEDON = @CREATEDON and 
                                              DELETED = @DELETED)
begin
INSERT INTO K2FILELOG
	   (FILEPATH, [FILENAME],FILETYPE,FILEDATE,CIRCLEID,TOTALROWS,SUCCESSCOUNT,FAILURECOUNT,PROCESSED,ERROR,VENDORID,CREATEDBY, CREATEDON, DELETED)
values (@FILEPATH ,@FILENAME,@FILETYPE,@FILEDATE,@CIRCLEID,@TOTALROWS,@SUCCESSCOUNT,@FAILURECOUNT,@PROCESSED,@ERROR ,@VENDORID,@CREATEDBY,@CREATEDON,@DELETED);
set @FILELOGID =@@identity
  END

ELSE if
begin
select count (CIRCLEID) from K2FILELOG with (nolock) where FILETYPE = @FILETYPE and	
                                                             FILEDATE = @FILEDATE and	
                                                             CIRCLEID = @CIRCLEID 
                                                             GROUP BY CIRCLEID having count(CIRCLEID) >= 4
END
else
begin
INSERT INTO K2FILELOG
	   (FILEPATH, [FILENAME],FILETYPE,FILEDATE,CIRCLEID,TOTALROWS,SUCCESSCOUNT,FAILURECOUNT,PROCESSED,ERROR,VENDORID,CREATEDBY, CREATEDON, DELETED)
values (@FILEPATH ,@FILENAME,@FILETYPE,@FILEDATE,@CIRCLEID,@TOTALROWS,@SUCCESSCOUNT,@FAILURECOUNT,@PROCESSED,@ERROR ,@VENDORID,@CREATEDBY,@CREATEDON,@DELETED);
set @FILELOGID =@@identity
end

END



Please Guide me .
Posted

Else If should have the conditional statment you have left it blank put the condition.
 
Share this answer
 
Comments
R Harshal 14-Jul-14 4:22am    
Yes I am confuse on same place.I want to perform this three Condition.
1 st Condition :If i found the same record in database,it should not save the Record.
2 nd Condition: New Record should get Add.
3 rd Condition:if i found more than 4 record for the same CircleId it should not allow to save.

will you Guide me ,Where should i need to modify the Stored Procedure.

Please Guide me.

Thanks Harshal
R Harshal 14-Jul-14 4:26am    
I made some mistake in Stored Procedure which I am not able to solve it.
Please Kindly Revert.
Thanks Harshal.
Hi,

First Change :

SQL
ALTER PROCEDURE [dbo].[K2_CHECKENTRYINFILELOG] (
@FILENAME VARCHAR(150),
@FILEPATH VARCHAR(MAX),
@FILETYPE int,
@FILEDATE datetime,
@CIRCLEID INT,
@TOTALROWS int,
@SUCCESSCOUNT int,
@FAILURECOUNT int,
@PROCESSED bit,
@ERROR varchar(MAX),
@VENDORID int,
@CREATEDBY INT = 1,
@CREATEDON DATETIME,
@DELETED BIT=0,
@FILELOGID bigINT
 )
AS


2nd Change:

Put a condition after else if, you have not written condition in else if.

Please make these changes, if after that you will get error then you can ask me again.
 
Share this answer
 
v2
Comments
R Harshal 14-Jul-14 5:06am    
Thanks for your reply .
But There is a twist in my stored Procedure .
I have make another stored PRocedure for saving the new Record.
In this Stored Procedure i need to check the existing Reccord.I want to perform only two condition.
1 st Condition :If i found the same record in database,it should not save the Record.
2 nd Condition:if i found more than 4 record for the same CircleId it should not allow to save.
What changes i need to make in my stored PRocedure,it gives me error :Incorrect syntax near the keyword 'ELSE'.

ALTER PROCEDURE [dbo].[K2_CHECKENTRYINFILELOG]
@FILENAME VARCHAR(150),
@FILEPATH VARCHAR(MAX),
@FILETYPE int,
@FILEDATE datetime,
@CIRCLEID INT,
@TOTALROWS int,
@SUCCESSCOUNT int,
@FAILURECOUNT int,
@PROCESSED bit,
@ERROR varchar(MAX),
@VENDORID int,
@CREATEDBY INT = 1,
@CREATEDON DATETIME,
@DELETED BIT=0,
@FILELOGID bigINT

AS
BEGIN
IF NOT EXISTS (
select count(CIRCLEID) from K2FILELOG where FILEPATH = @FILEPATH and
[FILENAME] = @FILENAME and
FILETYPE = @FILETYPE and
FILEDATE = @FILEDATE and
CIRCLEID = @CIRCLEID and
TOTALROWS = @TOTALROWS and
SUCCESSCOUNT = @SUCCESSCOUNT and
FAILURECOUNT = @FAILURECOUNT and
PROCESSED = @PROCESSED and
ERROR = @ERROR and
VENDORID = @VENDORID and
CREATEDBY = @CREATEDBY and
CREATEDON = @CREATEDON and
DELETED = @DELETED)


ELSE

begin
select count (CIRCLEID) from K2FILELOG with (nolock) where FILETYPE = @FILETYPE and
FILEDATE = @FILEDATE and
CIRCLEID = @CIRCLEID
GROUP BY CIRCLEID having count(CIRCLEID) >= 4
END


END
R Harshal 14-Jul-14 5:40am    
Hi Sarvesh.
Please kindly revert.
R Harshal 15-Jul-14 7:31am    
Dear Sarvesh,
I am still waiting for your answer.Please let me know.

Thanks
R Harshal 15-Jul-14 7:36am    
Anyone from the Code Project Team can tell me ,how to use If Exists statement for two condition ,As i got lot of confusion in my stored procedure ,Some the Engineer from Code MAster have closed my issue without giving the proper answer,as they says same issue was assign for number of times ,but if you check procedure are same but question are different.I dont know why they closed all those ticket .The Ticket which is open have not given reply from long time .would anyone from CodeMaster Team can help me from this situation.

Thanks in Advance
Harshal.
R Harshal 15-Jul-14 7:40am    
now the problem is if the same record is not present in database then to it gives me return as 1.This could not happen.Please find the latest Stored Procedure
ALTER PROCEDURE [dbo].[K2_CHECKENTRYINFILELOG]
@FILENAME VARCHAR(150),
@FILEPATH VARCHAR(MAX),
@FILETYPE int,
@FILEDATE datetime,
@CIRCLEID INT,
@TOTALROWS int,
@SUCCESSCOUNT int,
@FAILURECOUNT int,
@PROCESSED bit,
@ERROR varchar(MAX),
@VENDORID int,
@CREATEDBY INT = 1,
@CREATEDON DATETIME,
@DELETED BIT=0,
@FILELOGID BIGINT OUTPUT

AS
BEGIN



--IF EXISTS (
set @FILELOGID = (select count(CIRCLEID) as CircleId from K2FILELOG where FILEPATH = @FILEPATH and
[FILENAME] = @FILENAME and
FILETYPE = @FILETYPE and
FILEDATE = @FILEDATE and
CIRCLEID = @CIRCLEID and
TOTALROWS = @TOTALROWS and
SUCCESSCOUNT = @SUCCESSCOUNT and
FAILURECOUNT = @FAILURECOUNT and
PROCESSED = @PROCESSED and
ERROR = @ERROR and
VENDORID = @VENDORID and
CREATEDBY = @CREATEDBY and
CREATEDON = @CREATEDON and
DELETED = @DELETED)
--)

begin

select count (CIRCLEID) as CircleId from K2FILELOG with (nolock) where FILETYPE = @FILETYPE and
[FILENAME] = @FILENAME and
FILEPATH = @FILEPATH and
FILEDATE = @FILEDATE and
CIRCLEID = @CIRCLEID
GROUP BY CIRCLEID having count(CIRCLEID) >= 4

end

END

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900