Get Month - Common Function for SQL Server & Oracle
-
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..
-
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..
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
-
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..
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"!
-
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"!
-
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..
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.