The following SP gives an error of:
Server: Msg 245, Level 16, State 1, Procedure spSelectSEICData, Line
26
Syntax error converting the varchar value '@' to a column of data type
int.
In the Procedure I am using the Select * for testing purposes.
Here is the proc.
CREATE PROCEDURE spSelectSEICData
(
@IndivNo int,
@CommType SmallInt,
@BeginDate as SmallDateTime
)
AS
Declare @SqlStr as char(1)
Set @SqlStr = ''
If ((@BeginDate <> ' ') and (@CommType <> ' '))
Begin
Set @SqlStr = '@IndivNo AND [SEIC-COMMENT-TYPE] = @CommType'
End
If ((@BeginDate <> ' ') and (@CommType = ' '))
Begin
Set @SqlStr = '@IndivNo AND [SEIC-COMMENT-DATE-MCYMD] =
@BeginDate'
End
If ((@BeginDate = ' ') and (@CommType <> ' '))
Begin
Set @SqlStr = '@IndivNo AND [SEIC-COMMENT-DATE-MCYMD] = @BeginDate
AND[SEIC-COMMENT-TYPE] = @CommType '
End
If ((@BeginDate = ' ') and (@CommType = ' '))
Begin
Set @SQlStr = '@IndivNo '
End
SELECT *
FROM SEIC
WHERE [SEIC-INDIVIDUAL-NO] = @SqlStr
GO
The optional values are the @CommType and the @BeginDate. Where did I
go wrong or is there a better way of doing this?
Thanks in advance
Bill