Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Get Month - Common Function for SQL Server & Oracle

Get Month - Common Function for SQL Server & Oracle

Scheduled Pinned Locked Moved Database
databasesql-serveroraclesysadmintutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NTheOne
    wrote on last edited by
    #1

    Hello, Can any one tell me common function for SQL server and Oracle for getting month from the given date. For Example, In SQL Server --> CAST(DATEPART(Month , Booking.BookingDtTime) AS VARCHAR(20)) AS Month_Value In Oracle --> TO_CHAR(Booking.BookingDtTime, 'Month') AS Month_Value I want a common function for the same which works both in SQL Server as well Oracle. Thanks..

    M B J 3 Replies Last reply
    0
    • N NTheOne

      Hello, Can any one tell me common function for SQL server and Oracle for getting month from the given date. For Example, In SQL Server --> CAST(DATEPART(Month , Booking.BookingDtTime) AS VARCHAR(20)) AS Month_Value In Oracle --> TO_CHAR(Booking.BookingDtTime, 'Month') AS Month_Value I want a common function for the same which works both in SQL Server as well Oracle. Thanks..

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      NTheOne wrote:

      I want a common function for the same which works both in SQL Server as well Oracle.

      Good luck with that. They are different databases using different sql dialects (TSQL and PLSQL) what makes you thinks there is or should be a common function in each dialect. You are going to have to code around the differences and detect the type of database you are working against. [edit] One way would be to code your own function in each database and use the same name. Functions are on a roll this morning. [/edit]

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • N NTheOne

        Hello, Can any one tell me common function for SQL server and Oracle for getting month from the given date. For Example, In SQL Server --> CAST(DATEPART(Month , Booking.BookingDtTime) AS VARCHAR(20)) AS Month_Value In Oracle --> TO_CHAR(Booking.BookingDtTime, 'Month') AS Month_Value I want a common function for the same which works both in SQL Server as well Oracle. Thanks..

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        You will encounter many more differences between SQL Server's SQL and Oracle's SQL. When I made our application work with both of them, I created a framework for that. The "S" in SQL stands for "structured", not for "standard"!

        L 1 Reply Last reply
        0
        • B Bernhard Hiller

          You will encounter many more differences between SQL Server's SQL and Oracle's SQL. When I made our application work with both of them, I created a framework for that. The "S" in SQL stands for "structured", not for "standard"!

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          There's ANSI-92 SQL, and Sql Server supports that. Doesn't Oracle have something similar?

          I are Troll :suss:

          1 Reply Last reply
          0
          • N NTheOne

            Hello, Can any one tell me common function for SQL server and Oracle for getting month from the given date. For Example, In SQL Server --> CAST(DATEPART(Month , Booking.BookingDtTime) AS VARCHAR(20)) AS Month_Value In Oracle --> TO_CHAR(Booking.BookingDtTime, 'Month') AS Month_Value I want a common function for the same which works both in SQL Server as well Oracle. Thanks..

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Why? I would suspect there isn't one. If you are attempting SQL independence that means you can't use stored procs and must be using another language to wrap it, so just use that language to extract the month. If using in a where clause then construct an appropriate timestamp value that represents a month range. This has the advantage that it is probably faster as well.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups