Solved

How to format the oracle date to get the YYMMDD from SQLSERVER

Posted on 2008-06-09
4
966 Views
Last Modified: 2012-08-13
I have the below query and I'm trying to get the results from Oracle database using
linked server in Sqlserver. I'm trying to use the to_date function to get the YYMMDD
format but I'm getting the below error. Please let me know how to get full date.

ERROR:

An error occurred while preparing a query for execution against OLE DB provider 'MSDAORA'.
[OLE/DB provider returned message: ORA-00904: "MMYYDD": invalid identifier
]
OLE DB error trace [OLE/DB Provider 'MSDAORA' ICommandPrepare::Prepare returned 0x80040e14].


MY QUERY:

SELECT *
FROM OPENQUERY (GL_PROD_WRITE, 'SELECT Invoice_Number, Billed_Road, Invoice_Date, Rptg_Mk, Car_Num, Ref_Document, Repairing_Party, Currency, Detail_Source,
        Car_Type, Load_Empty_Ind, to_date(Ship_Date,"MMYYDD"), SPLC_Code, Repair_Pty_Invoice, Repair_Pty_Document, Facility_Type, Loc_On_Car, Quantity,
        Applied_Job_Cd, Applied_Qualifier, Why_Made, Removed_Job_Code, Removed_Qualifier, Resp, Defect_Card_Party, Defect_Card_Date,
        Material_Sign, Machine_Priceable, Wrong_Repair, Narrative, Car_Class, FM_Cd, Mobile_Repair, ARI_Cust_Number, Currency_Multiplier,
        Labor_AMT_US_Dols, Material_Amt_US_Dols, C_BRCEXT_SHP_CD, Condition FROM GL_PROD.C_BRCEX
0
Comment
Question by:vmandem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:knowledge_riot
ID: 21746339
Try putting the date format, MMYYDD in single quotes (not double quotes)

See: http://www.dba-oracle.com/f_to_date.htm
0
 

Author Comment

by:vmandem
ID: 21750844
Hi, whether you noticed or not that my Whole query is already in single quotes and If I give single quotes again around the format('MMDDYYYY') it is giving me Incorrect Syntax near 'MMDDYYYY'. If I remove the quotes like MMDDYYYY then I get the error

An error occurred while preparing a query for execution against OLE DB provider 'MSDAORA'.
[OLE/DB provider returned message: ORA-00904: "MMDDYYYY": invalid identifier
]
OLE DB error trace [OLE/DB Provider 'MSDAORA' ICommandPrepare::Prepare returned 0x80040e14].


Please let me know what to do in this scenario.
0
 
LVL 2

Accepted Solution

by:
knowledge_riot earned 50 total points
ID: 21767105
OK, it is difficult to see from the text above what sort of quotes you have around MMDDYYYY, but it looks like they are double quotes

On my keyboard I have double quotes like this " and single quotes like this '

As your SQL statement is already in single quotes, we need to escape any further single quotes in the SQL, so can you try putting 2 single quotes at the start and another 2 single quotes at the end of so we end up like this ''MMDDYYYY'' (Which looks the same as "MMDDYYYY" but means something different)

Best way to see the difference would be to paste my answer into notepad and check carefully the number of characters around MMDDYYYY in the 2 examples above
0
 

Author Closing Comment

by:vmandem
ID: 31465539
Good
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

728 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