本文介绍了创建存储过程时,SQL Server中的“=”错误附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表bankcheques,check和chequedetails现在我创建了

的程序如果bank_id,bankchequeno不存在于bankcheques表insert record.while更新记录我正在检查两个条件,如果chequedetails表中不存在chequeno,则更新bankcheques表中的每个字段。

如果chequedetails表中存在chequeno,则只更新bankcheques表中的status字段。在这里我检查另一个条件。

i我从支票表中根据bankid和chequeend从bankcheques表中获取maxcheueno并比较这两个值然后更新bankcheque表的状态。我在'='附近得到错误的语法错误请帮帮我。谢谢你。



我尝试过的事情:



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:

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

推荐答案

if(@chqlastno==@lastcheueno)

SQL不使用==作为条件,而是使用=代替。

SQL does not use "==" for conditionals, it uses "=" instead.


这篇关于创建存储过程时,SQL Server中的“=”错误附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 23:59