I have problem with basic if condition in function.. I have something like this
IF LEFT(@text, 1) = '#'
BEGIN
/* trim first character if is '#' */
RETURN RIGHT(@text,LEN(@text)-1)
END
ELSE
BEGIN
RETURN @text
END
END
Console output show me this
Incorrect syntax near the keyword 'IF'. Incorrect syntax near the keyword 'END'.
I wonder where the problem is. Can I simplify the if condition like this?
IF LEFT(@text, 1) = '#' RETURN RIGHT(@text,LEN(@text)-1)
ELSE RETURN @text
Thank you
edit: now I have that if in function
CREATE FUNCTION Trimming (@text VARCHAR(255))
RETURNS VARCHAR(255)
AS
BEGIN
DECLARE @TrimText AS VARCHAR(255) ;
SET @TrimText=LTRIM(RTRIM(@text)
IF LEFT(@TrimText, 1) = '#'
BEGIN
RETURN RIGHT(@TrimText,LEN(@TrimText)-1)
END
ELSE
BEGIN
RETURN @TrimText
END
END
and console says
Incorrect syntax near the keyword 'IF'.