This is my code:
-- Create Function
if object_id('dbo.J_TRIM') is not null drop function dbo.J_TRIM
GO
CREATE FUNCTION dbo.J_TRIM(@string VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@string)) AS [@string]
END
GO
SELECT dbo.J_TRIM(Supplier) FROM Supplier_List
It all works apart from when I try to set the column name as the string by using AS [@string]. Is this possible in SQL, and if so, how do I fix my code?
SELECT.LTRIM(RTRIM(...))every time or (if reusing the logic actually pays off, like it does not here) rewriting the function as an inline table-valued function. Unlearn what you know from languages actually designed for programming.