hi.
I have this:
alter FUNCTION teste (@div nvarchar(10), @dep nvarchar(10), @sec nvarchar(10)) RETURNS @lista TABLE ( mdnemp int primary key NOT NULL, mdnome nvarchar(50) NOT NULL, mvdivs nvarchar(50) NOT NULL, mvdept nvarchar(50) NOT NULL, mvsecc nvarchar(50) NOT NULL ) as begin DECLARE @SelectStatement NVARCHAR(2000) if @div != '' begin set @SelectStatement = 'select mdnemp, mdnome, mvdivs, mvdept, mvsecc from colbrdor where MVDIVS = '+ @div end if @dep != '' begin if @SelectStatement != '' set @SelectStatement = @SelectStatement + ' and MVDEPT = '+ @dep else set @SelectStatement = 'select mdnemp, mdnome, mvdivs, mvdept, mvsecc from colbrdor where MVDEPT = '+ @dep end if @sec != '' begin if @SelectStatement != '' set @SelectStatement = @SelectStatement + ' and MVSECC = '+ @sec else set @SelectStatement = 'select mdnemp, mdnome, mvdivs, mvdept, mvsecc from colbrdor where MVSECC = '+ @sec end insert into @lista ( exec sp_Executesql @SelectStatement ) return end
i get and error in the line
insert into @lista ( exec sp_Executesql @SelectStatement )
where is my problem?
Thank's in advance.