CompCodeBoy
Programmer
Guys,
I need help with this T-SQL syntax. I can not get it to work. I got a stored procedure that does a simple search.
here it is:
CREATE PROCEDURE [dbo].[usp_Search]
@reqno int ,
@deptno int
AS
SET NOCOUNT ON
DECLARE @strSQL varchar(1200)
DECLARE @check bit
SET @check = 0
SET @strSQL = 'SELECT *,teams.team_autonumber,team_name,departments.department_No,departments.department_Name--,projectstatuscodes.projectstatuscode,projectstatuscodes.projectstatuscodeDesc
FROM OpenIssues inner join teams ON teams.team_autonumber=openissues.team_assigned_to inner join Departments ON openissues.Req_Dept_No=Departments.department_No'
SET @strSQL = @strSQL + ' WHERE date_requested>''01/01/1900'''
IF (@reqNo > 0)
BEGIN
SET @strSQL = @strSQL + ' AND ( req_autonumber = cast (''@reqno'' AS int) '
SET @check = 1
END
IF @check =1
SET @strSQL = @strSQL + ' )'
EXEC (@strSQL)
My problem is on this line
SET @strSQL = @strSQL + ' AND ( req_autonumber = cast (''@reqno'' AS int) '
The error I get is:
"Syntax error converting the varchar value '@reqno' to a column of data type int. "
When I replace @reqno with an integer like 22 the stored procedure works just as expected. I took cast off and still got the same result. What Am I missing here ? Thank!
I need help with this T-SQL syntax. I can not get it to work. I got a stored procedure that does a simple search.
here it is:
CREATE PROCEDURE [dbo].[usp_Search]
@reqno int ,
@deptno int
AS
SET NOCOUNT ON
DECLARE @strSQL varchar(1200)
DECLARE @check bit
SET @check = 0
SET @strSQL = 'SELECT *,teams.team_autonumber,team_name,departments.department_No,departments.department_Name--,projectstatuscodes.projectstatuscode,projectstatuscodes.projectstatuscodeDesc
FROM OpenIssues inner join teams ON teams.team_autonumber=openissues.team_assigned_to inner join Departments ON openissues.Req_Dept_No=Departments.department_No'
SET @strSQL = @strSQL + ' WHERE date_requested>''01/01/1900'''
IF (@reqNo > 0)
BEGIN
SET @strSQL = @strSQL + ' AND ( req_autonumber = cast (''@reqno'' AS int) '
SET @check = 1
END
IF @check =1
SET @strSQL = @strSQL + ' )'
EXEC (@strSQL)
My problem is on this line
SET @strSQL = @strSQL + ' AND ( req_autonumber = cast (''@reqno'' AS int) '
The error I get is:
"Syntax error converting the varchar value '@reqno' to a column of data type int. "
When I replace @reqno with an integer like 22 the stored procedure works just as expected. I took cast off and still got the same result. What Am I missing here ? Thank!