I'm stuck trying to create a function to display customer names based on area code.
Function is created, but I'm getting null results for known area codes where I should be getting lots.
I'm a clueless newbie, and that may be a factor.
alter function ufnGetCustomerByAreaCode(@AreaCode nvarchar(3))
returns nvarchar(100)
as
begin
declare @Customer as nvarchar(100);
set @Customer =
(
select c.FirstName + ' ' + c.LastName
from SalesLT.Address as a
join SalesLT.CustomerAddress as ca
on a.AddressID = ca.AddressID
join SalesLT.Customer as c
on ca.CustomerID = c.CustomerID
where left(a.PostalCode,3) = @AreaCode
)
return @Customer
end
Using the command
select dbo.ufnGetCustomerByAreaCode(706)
I'm getting null results. The table has lots of 706 area codes.
@Customerhold them all? Don't you need to return 1 value from the select?CustomerAddresswhich match for example.