hunterspot
Programmer
Hi
I have written this stored procedure to delete records from a look up table. The table has only two fields and the structure is:
1. code varchar(4)
2. description varchar(150).
Here is the code of the stored proc.:
************
-- ================================================================
-- Author: *******
-- Create date: 02/05/2010
-- Description: Deletes record in the Table
-- =================================================================
CREATE PROCEDURE [dbo].[usp_Delete_From_Lookuptable]
(
@TableName varchar(50)
,@Code varchar(4)
)
AS
BEGIN
SET NOCOUNT ON
SET @TableName = RTRIM(@TableName)
declare @sqlstring varchar(250)
set @sqlstring = 'delete from ' + @tablename + 'where code = ' + @code
exec(@sqlstring)
IF @@ERROR = 0 AND @@ROWCOUNT = 1
BEGIN
RETURN 1
END
ELSE
BEGIN
RAISERROR('Error while Deleting from the table', 16,1)
RETURN -1
END
END
GO
**************
This is giving error "Syntax Error converting the varchar value 'A1' tp column of data type Int.
Will you please tell me how to fix this?
Thanks in advance.
I have written this stored procedure to delete records from a look up table. The table has only two fields and the structure is:
1. code varchar(4)
2. description varchar(150).
Here is the code of the stored proc.:
************
-- ================================================================
-- Author: *******
-- Create date: 02/05/2010
-- Description: Deletes record in the Table
-- =================================================================
CREATE PROCEDURE [dbo].[usp_Delete_From_Lookuptable]
(
@TableName varchar(50)
,@Code varchar(4)
)
AS
BEGIN
SET NOCOUNT ON
SET @TableName = RTRIM(@TableName)
declare @sqlstring varchar(250)
set @sqlstring = 'delete from ' + @tablename + 'where code = ' + @code
exec(@sqlstring)
IF @@ERROR = 0 AND @@ROWCOUNT = 1
BEGIN
RETURN 1
END
ELSE
BEGIN
RAISERROR('Error while Deleting from the table', 16,1)
RETURN -1
END
END
GO
**************
This is giving error "Syntax Error converting the varchar value 'A1' tp column of data type Int.
Will you please tell me how to fix this?
Thanks in advance.