Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a tables bankcheques,cheques and chequedetails now i create the procedure for
if bank_id,bankchequeno doesn't exist in bankcheques table insert record.while updating the record i am checking two conditions if chequeno not exists in chequedetails table update every field from the bankcheques table.
and if chequeno exists in chequedetails table only update the status field in the bankcheques table. here iam checking another condition.
i am taking maxcheueno from cheques table based on bankid and chequeend from bankcheques table and compare the both values then update status of bankcheque table.I am getting the incorrect syntax near '=' Error Please help me on this.Thanks in Advance.

What I have tried:

SQL
USE [ChequeManager]
GO
/****** Object:  StoredProcedure [dbo].[Insertupdatebankcheques_iu]    Script Date: 06/17/2017 09:10:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    ALTER procedure [dbo].[Insertupdatebankcheques_iu]  
   (@bank_Id int   
   ,@bankslno int
  ,@bankChqstartno nvarchar(6)  
  ,@bankChqlvscount smallint  
  ,@bankChqendno nvarchar(6)
  ,@bank_Stat  bit
  ,@InsUpdt bit)  
  as  
  begin 
   declare @lastcheueno as int
   declare @chqlastno as int 
   select @lastcheueno= max([ChequeNo]) FROM [ChequeManager].[dbo].[Cheques] where [bank_Id]=@bank_Id  
  SELECT @chqlastno= [bank_Chqendno]  FROM [ChequeManager].[dbo].[bankcheques] where bank_Id=@bank_Id and bank_Slno=@bankslno 
   if(@InsUpdt=1)
  begin    
  if not exists(select bank_Id,bank_Chqstartno
      FROM [ChequeManager].[dbo].[bankcheques]
     where bank_Id=@bank_Id)
  begin
 INSERT INTO [ChequeManager].[dbo].[bankcheques]  
           (bank_Id,
           bank_Slno,
           [bank_Chqstartno]  
           ,[bank_Chqlvscount]  
           ,[bank_Chqendno]
           ,bank_Stat)  
             
           values( @bank_Id,
           @bankslno
            ,@bankChqstartno   
           ,@bankChqlvscount  
           ,@bankChqendno,
           @bank_Stat)  
  end  
  end
  if(@InsUpdt=0)  
  begin     
  if not exists(select chqs_Chequeno
      FROM [ChequeManager].[dbo].[chequedetails]
     where bank_Id=@bank_Id)
  begin
  UPDATE [ChequeManager].[dbo].[bankcheques]  
  set bank_Chqstartno=@bankChqstartno,
  bank_Chqlvscount=@bankChqlvscount,
  bank_Chqendno=@bankChqendno,
      [bank_Stat]=@bank_Stat
      ,[bank_Mstmp] = getdate()  
       WHERE bank_Id=@bank_Id  and [bank_Slno]=@bankslno
  end   
  end     
 if exists(select chqs_Chequeno FROM [ChequeManager].[dbo].[chequedetails] where bank_Id=@bank_Id)
  begin
  if(@chqlastno==@lastcheueno)
  begin
 UPDATE [ChequeManager].[dbo].[bankcheques]  
  set  [bank_Stat]=@bank_Stat
      ,[bank_Mstmp] = getdate()  
       WHERE bank_Id=@bank_Id  and [bank_Slno]=@bankslno
 end
 end
 end
Posted
Updated 16-Jun-17 20:08pm
v2

1 solution

Look here:
if(@chqlastno==@lastcheueno)
SQL does not use "==" for conditionals, it uses "=" instead.
 
Share this answer
 
Comments
Member 13153537 17-Jun-17 1:49am    
Thanks for the help it is fixed now.
OriginalGriff 17-Jun-17 2:15am    
You're welcome!
(I've done the same thing soooo many times myself!)
Member 13153537 28-Aug-17 1:09am    
I have created a stored procedure in mysql in that i created handler.one is 1064 handler another one is 1264. 1064 is working fine but 1264 is not working.Do you have knowledge on mysql please help me thanks in advance.


DELIMITER $$
CREATE PROCEDURE insert_article_tags_2(IN article_id INT, IN tag_id INT)
BEGIN

declare exit handler for sqlexception
select 'sql exception invoked';


DECLARE EXIT HANDLER FOR 1062

SELECT 'MySQL error code 1062 invoked';

DECLARE EXIT HANDLER FOR 1264

SELECT 'Out of range exception';


-- insert a new record into article_tags
INSERT INTO article_tags(article_id,tag_id)
VALUES(article_id,tag_id);

END

--showing 1062 error correct

call insert_article_tags_2(1,1)


--it is not showing out of range errror
call insert_article_tags_2(155555555555555,1877777755555555555)

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