Skyscraper

lunes, 1 de octubre de 2012

Oracle LAST_DAY function in SQL Server


Today I was working in SQL Server 2008. I need to use a function similar to Oracle's LAST_DAY in my scripts, but I cannot find an equivalent function, so I decided to perform a new one.

This is the script to build the function in SQL Server:



CREATE FUNCTION [dbo].[LAST_DAY] ( @pInputDate    DATETIME )
RETURNS DATETIME
BEGIN

    DECLARE @vOutputDate        DATETIME

    SET @vOutputDate = CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' +
                       CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/01'
    SET @vOutputDate = DATEADD(DD, -1, DATEADD(M, 1, @vOutputDate))

    RETURN @vOutputDate

END


These are the test scripts in SQL Server and Oracle:


  • SELECT dbo.LAST_DAY(getdate())



  • SELECT LAST_DAY(TRUNC(SYSDATE)) FROM dual

The result row in both scripts was: 2012-10-31 00:00:00.000

2 comentarios:

  1. Hello Everyone !

    USA SSN Leads/Fullz available, along with Driving License/ID Number with good connectivity.

    All SSN's are Tested & Verified.

    **DETAILS IN LEADS/FULLZ**

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER
    ->ADDRESS WITH ZIP
    ->PHONE NUMBER, EMAIL
    ->EMPLOYEE DETAILS

    *Price for SSN lead $2
    *You can ask for sample before any deal
    *If you buy in bulk, will give you discount
    *Sampling is just for serious buyers

    ->Hope for the long term business
    ->You can buy for your specific states too

    **Contact 24/7**

    Whatsapp > +923172721122

    Email > leads.sellers1212@gmail.com

    Telegram > @leadsupplier

    ICQ > 752822040

    ResponderEliminar