I am trying to make the procedure where I can get the data from MS SQL. Here I am getting the error
Msg 245, Level 16, State 1, Procedure GET_FUNCTIONS, Line 15 [Batch Start Line 33] Conversion failed when converting the varchar value ' and f.FUNCTION_ID in '' to data type int.
CREATE procedure [dbo].[GET_FUNCTIONS]
@Function_Id int,
@EntityId int,
@OrderBy varchar(10)
as
begin
declare @Sql nvarchar(max)
if(@Function_Id=0 AND @EntityId=0)
set @Sql = 'select
f.Function_Code,f.FUNCTION_ID,f.EntityId,be.ENTITY_SHORT_NAME,f.FUNCTION_NAME,
f.FUNCTION_DESC,f.CREATED_DATE,f.MODIFIED_DATE from FUNCTIONS f
inner join BusinessEntity be on f.EntityId=be.ID
WHERE f.ACTIVE=1 '
if(@Function_Id!=0)
set @Sql += ' and f.FUNCTION_ID in ''' + @Function_Id + ''''
if(@EntityId!=0)
set @Sql += ' and f.EntityId = cast('+convert(varchar(12) ,@EntityId)+') '
set @Sql += ' order by FUNCTION_ID '+ @OrderBy
print @Sql
end
GO