I have to make an insert in SQL Server.
I have tried the following, but I do not know if it will be fine, at first glance it gives me a fault near the IF
and the THEN
, but I do not know why. I imagine it will be for the AND
of the condition.
USE [BD]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spInsertRatio]
@descripcion varchar(255),
@pHora int,
@pPrecio int,
@pIdZona int,
@codigo_msg INT OUT,
@existeh int,
@existep int
AS
SET NOCOUNT ON;
BEGIN
Begin Tran TransInsertRatio
Begin Try
set @existeh = (select horasRD FROM dbo.TBLRatioDescuento where horasRD = 20)
set @existep = (select DescuentoRD FROM dbo.TBLRatioDescuento where DescuentoRD = 20)
IF @existeh IS NULL AND @existep IS NULL THEN
INSERT INTO [TBLRatioDescuento] ([idZona],[descripcionRD],[horasRD],[descuentoRd])
VALUES (2, "Máximo 20 h",20,20)
END IF;
End try
Begin Catch
set @codigo_msg = 1
Rollback TRAN TransInsertVehiculo
End Catch
END
The error message is as follows:
Mens 156, Nivel 15, Estado 1, Procedimiento spInsertRatio, Línea 17 Sintaxis incorrecta cerca de la palabra clave 'THEN'. Mens 156, Nivel 15, Estado 1, Procedimiento spInsertRatio, Línea 21 Sintaxis incorrecta cerca de la palabra clave 'IF'.