This is my SQL function
IF OBJECT_ID (N'dbo.limit','FN' ) IS NOT NULL
DROP FUNCTION limit;
Go
create function dbo.limit(@State_code varchar)
RETURNS nvarchar(max)
AS
BEGIN
DECLARE @ret varchar(max) ;
SELECT @ret = State_Name
FROM aqs_sites
WHERE aqs_sites.State_Code = @State_code and State_Name not like '%guam%'
RETURN @ret ;
END
When I call this function in my select syntax
go
select distinct [dbo].limit(aqs_sites.State_Code) from aqs_sites
I got a NULL result, really have no idea on it. BTW, I use SQL-server 2018.
select aqs_sites.*, [dbo].limit(aqs_sites.State_Code) from aqs_sites. Also, your return types don't match; the function returns avarcharwhile the signature says it'll returnnvarchar. Why not make them match?