I have created a scalar function that is supposed to spit out a date in a specific format based on a variable. for some reason i get an error around the "else"
what am i doing wrong ?
CREATE FUNCTION [dbo].[fGetDateformat] (@datum datetime,@CNotation char(2))
/* accepts datum and CNotation
USAGE:
select fGetDateformat(datum, "EN" or "DE") */
returns varchar(25) AS
BEGIN
declare @ReturnStr varchar(25)
if @Cnotation = 'DE'
set language german
set @ReturnStr =
DATENAME(dd, @datum)+'. '+DATENAME(MM, @datum)+' '+ DATENAME(YEAR, @datum)
else
set @ReturnStr = DATENAME(mm, @datum)+' '+DATENAME(dd, @datum)+', '+ DATENAME(YEAR, @datum)
return @ReturnStr
END
GO
If a T-SQL block spans multiple lines, you have to enclose it in begin
and end
. For example, this won't work:
if 1=1
print 'One is one!'
print 'Yay'
else
print 'Huh?'
This will:
if 1=1
begin
print 'One is one!'
print 'Yay'
end
else
print 'Huh?'
Note that print 'Huh?'
is still okay, since it is a single line.