Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

TSQL Scalar Function using select inside the function & excluding date

Avatar of Leogal
LeogalFlag for United States of America asked on
Microsoft SQL Server 2008
5 Comments1 Solution552 ViewsLast Modified:
I apologize in advance for asking what is likely a basic question, problem is that I am new to SQL and having difficulties with the syntax.

I am writing this function:

Alter function dbo.Fn_get_last_day
(@FN_InputDt               datetime

Returns      @d
as
begin

declare @d    datetime
    set    @d  = @FN_InputDt

select @d =
                   case when @FN_InputDt = 0 then 0 else
                            select day (@Fn_InputDt) DatePart(d,@FN_InputDt)
                    end

Return

End

Here are the errors returned:
Msg 156,  Level 15, State 1, Procedure FN_GET_LAST_DAY , line 16
incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Procedure FN_GET_LAST_DAY, line 16
Incorrrect syntax near 'D'
Msg 102, Level 15, State 1, Procedure FN_GET_LAST_DAY, line 21
Incorrect syntax near 'END'