From SQL Server , I need to be able to pull some information from an Oracle database based on a date column.
SET @foo = 'SELECT * from OPENQUERY(' + @LinkedServer +
', ''SELECT *
FROM Table1
WHERE date_revised > '''''+@myDate+'''''')'
Don't mind if the numbers of ' is off... I cut things out to make this shorter. I have tried using convert() on the SQL Server side, but I cannot seem to find a format that Oracle accepts, so it keeps throwing errors.
At a minimum, I require date, hours, and minutes. When testing values in SQL Developer (Oracle) to figure out acceptable formats, I keep running into this behavior:
select to_date('2010-11-15 12:21:00', 'yyyy/mm/dd hh:mi:ssam') from dual
15-NOV-10
Clearly, I specify I want time, but it just doesn't agree with me. I've been stuck on this issue way too long.
In short, how do I format a SQL Server datetime into a format that Oracle's to_date function will accept, and how do I make that function properly show date and time?
DATEhas no format. Formatting of aDATEvalue is done by the client, not the server (and that's what you see). If you need the output in a specific format you need to useto_char()(on the Oracle side). See here: sqlfiddle.com/#!4/d41d8/4378@myDateas specified above, I would need to have that be avarcharright? When I typecast adatetime -> varchar, doesn't it become formatted in some manner? I tried your suggestion of using to_char instead, but I get the error:OLE DB provider "OraOLEDB.Oracle" for linked server "TED_IMCD" returned message "ORA-01841: (full) year must be between -4713 and +9999, and not be 0".The dynamic sql get evaluated toWHERE date_revised > to_char(timestamp 'Nov 15 2012 11:12AM', 'YYYY.MM.DD HH24:MI:SS')to_char(timestamp 'Nov 15 2012 11:12AM', 'YYYY.MM.DD HH24:MI:SS')is not implementing the prior answer.timestamp '...'the format must be ISO (the way I showed it in my SQLFiddle). It's the (ANSI) SQL standard to specify date literals. You cannot use any arbitrary format for a SQL date literal like that.