I am creating a function to return the full name of a customer when a customer id is entered:
CREATE FUNCTION displayName
(
@customer_id int
)
RETURNS varchar(50)
AS
BEGIN
DECLARE @name varchar(50)
SELECT @name = (SELECT name_first + ' ' + name_last AS FULL_NAME FROM DT_CUSTOMERS WHERE customer_id = @customer_id)
RETURN @name
END
GO
Is something wrong with my code? How do I run it?
SELECT dbo.displayName(42)2. if you concatenate NULL with string, the result is NULL, so if eitherfirst_nameorlast_nameare null, the result is NULL.