I have problem compilin this code..can anyone tell whats wrong with the syntax
CREATE PROCEDURE spGenericInsert
(
@insValueStr nvarchar(200)
@tblName nvarchar(10)
)
AS
BEGIN
DECLARE @insQueryStr nvarchar(400)
DECLARE @insPrimaryKey nvarchar(10)
DECLARE @rowCountVal integer
DECLARE @prefix nvarchar(5)
IF @tblName='HW_Master_DB'
SET @rowCountVal=(SELECT COUNT(*) FROM HW_Master_DB)
ELSE IF @TableName='SW_Master_DB'
SET @rowCountVal=(SELECT COUNT(*) FROM SW_Master_DB)
ELSE IF @TableName='INV_Allocation_DB'
SET @rowCountVal=(SELECT COUNT(*) FROM INV_Allocation_DB)
ELSE IF @TableName='REQ_Master_DB'
SET @rowCountVal=(SELECT COUNT(*) FROM REQ_Master_DB)
IF @tblName = 'DEFECT_LOG'
SET @prefix='DEF_'
ELSE IF @tblName='INV_Allocation_DB'
SET @prefix='INV_'
ELSE IF @tblName='REQ_Master_DB'
SET @prefix='REQ_'
ELSE IF @tblName='SW_Master_DB'
SET @prefix='SWI_'
ELSE IF @tblName='HW_Master_DB'
SET @prefix='HWI_'
SET @insPrimaryKey= @prefix + RIGHT(replicate('0',5)+ convert(varchar(5),@rowCountVal),5) -- returns somethin like 'DEF_00005'
SET @insQueryStr= 'INSERT INTO ' + @tblName + ' VALUES (' + @insPrimaryKey + ',' + @insValueStr + ')'
EXEC(@insQueryStr)
END