I have written the following SP. This can have have aany or all of the 3 parameters.
In Enterprise Manager, on checking the syntax of the SP it says it is OK. When I try and test this in QA I get the following message :
'Syntax error converting varchar value 'and hospcode =' to a column of data type int'
HELP .... Please ...
Thanks
Suel
In Enterprise Manager, on checking the syntax of the SP it says it is OK. When I try and test this in QA I get the following message :
'Syntax error converting varchar value 'and hospcode =' to a column of data type int'
HELP .... Please ...
Thanks
Suel
Code:
CREATE PROCEDURE slFind_Errors_Rpt
@hcode int = null,
@survyear int = null,
@speriod int = null
as
declare @select varchar(255)
declare @from varchar(255)
declare @where varchar(255)
select @select = 'select serialnum,hospcode,errorid,syear,survperiod '
select @from = 'from errorlog'
select @where = ''
if @hcode is not null
begin
select @where = @where + ' and hospcode = ''' + @hcode + ''''
end
if @survyear is not null
begin
select @where = @where + ' and syear = ''' + @survyear + ''''
end
if @speriod is not null
begin
select @where = @where + ' and survperiod = ''' + @speriod + ''''
end
if datalength(@where) <> 0
begin
select @where = stuff(@where,1,4,'where')
end
print @select + @from + @where
--exec(@select + @from + @where)
GO