How to replace DateSerial in SQL Server Stored Procedure ?

Posted on 2005-04-11
Last Modified: 2008-02-01
The following statement works fine in my Access application but when I moved it into SQL Server as a stored procedure,
I get the error message:

Error 195: DateSerial is not a recognized function name:

((tblCustomers.DateLost)<=DateSerial(Year(#" & Me.dtFullDate & "#)-[tblStatesAll].[BondsFS],6,30))

Could you tell me what function I could use to replace DateSerial in the context I am using it above. I would really appreciate it if you could show me the implementation of the replacement function in my SQL statement above.
The value returned by tblStatesAll.BondsFS is an integer value between 1 and 5. For example if BondsFS is 4 and
Me.dtFullDate is 1/1/2004. The DateSerial(Year(#1/1/2004#)-4,6,30) is 6/30/2004. Thus, the result is
DateLost <= 6/30/2000 in my example.

My question is how would I write this in SQL Server stored procedure since I cannot use DateSerial.
Question by:zimmer9
    LVL 36

    Expert Comment

    LVL 11

    Accepted Solution

    If you want to return as string:

    If you want to return as date:


    Create Procedure dbo.myProc (@dtFullDate datetime, @iBondsFS int) AS

    SELECT ....
    FROM   ....
    WHERE (tblCustomers.DateLost < convert(datetime,'6/'+'30/'+convert(varchar(4),datepart(yy,@dtFullDate)-@iBondsFS),101))
         OR (tblCustomers.DateLost = convert(datetime,'6/'+'30/'+convert(varchar(4),datepart(yy,@dtFullDate)-@iBondsFS),101))

    Author Comment

    Could you explain the last value ,101 ?
    LVL 11

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now