SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Simple pass thru query


Simple pass thru query

Author
Message
Phunhog
Phunhog
Say Hey Kid
Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)

Group: General Forum Members
Points: 696 Visits: 220
Hello Oracle Forum:

I've got my first linked server established from SQL Server 2008 SSMS to Oracle.
What is the proper syntax for this simple query with a date expression in the where clause?
What is the proper date delimiter?
Is there a conversion necessary?

SELECT TOP (5) SURGERY_DATE
FROM OPENQUERY(CLARITY, 'SELECT * FROM OR_LOG WHERE SURGERY_DATE = ('8/1/2012')' AS a

Many thanks ahead of time.

Phunhog
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26667 Visits: 4639
Phunhog (8/20/2012)

Hello Oracle Forum:

I've got my first linked server established from SQL Server 2008 SSMS to Oracle.
What is the proper syntax for this simple query with a date expression in the where clause?
What is the proper date delimiter?
Is there a conversion necessary?

SELECT TOP (5) SURGERY_DATE
FROM OPENQUERY(CLARITY, 'SELECT * FROM OR_LOG WHERE SURGERY_DATE = ('8/1/2012')' AS a


First, there is no TOP clause on Oracle - if you want the first five rows returned you have to wrap-up the query like this...

select *
from
(
type-here-your-query-including-order-by-clause
)
where rownum < 6;

Second, assuming SURGERY_DATE is of the DATE data type syntax should go like...
... where SURGERY_DATE = TO_DATE('08/01/2012', 'mm/dd/yyyy')

This is assuming 08 represents the month and 01 represents the day on the month.

_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Phunhog
Phunhog
Say Hey Kid
Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)

Group: General Forum Members
Points: 696 Visits: 220
Many thanks Mr. Berzuko:

Your expression works quite well!
My complete pass thru query looks like this:

SELECT LOG_ID, LOG_NAME, SURGERY_DATE
FROM OPENQUERY(CLARITY, 'SELECT * FROM OR_LOG WHERE SURGERY_DATE = TO_DATE(''08/01/2012'', ''mm/dd/yyyy'')') AS a

Note the addition of the doubled up single quotation marks for delimiters. (Whats the correct term for this?)
The inner derived table is a text string delimited by single quotes. AND the date expression(s) are ALSO delimited by single quotes. So the final concatenated string has doubled up single quotation marks.

THANKS for the help!
I may have more pass thru query questions.

Phunhog
Jo Pattyn
Jo Pattyn
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13156 Visits: 10244
Hint: rewrite select * to the actual field names.
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26667 Visits: 4639
Phunhog (8/21/2012)

Many thanks Mr. Berzuko:

Your expression works quite well!
/ / /
Note the addition of the doubled up single quotation marks for delimiters. (Whats the correct term for this?)


Glad it worked fine Phunhog. "Delimiter(s)" is fine.

_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Phunhog
Phunhog
Say Hey Kid
Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)Say Hey Kid (696 reputation)

Group: General Forum Members
Points: 696 Visits: 220
One last question for Pablo or the oracle forum regarding dates in this SQL

SELECT LOG_ID, LOG_NAME, SURGERY_DATE
FROM OPENQUERY(CLARITY, 'SELECT * FROM OR_LOG WHERE SURGERY_DATE = TO_DATE(''08/01/2012'', ''mm/dd/yyyy'')') AS a

What is the proper expression to select yesterdays records rather than august first?

Is it WHERE SURGERY_DATE = TO_DATE((CURRENT_DATE, ''mm/dd/yyyy'')-1)

many thanks ahead of time

Phunhog
Jo Pattyn
Jo Pattyn
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13156 Visits: 10244
SELECT LOG_ID, LOG_NAME, SURGERY_DATE
FROM OPENQUERY(CLARITY, 'SELECT * FROM OR_LOG WHERE SURGERY_DATE >= trunc(sysdate-1) and SURGERY_DATE <trunc(sysdate)')

Please do not use where trunc(surgery_date)=trunc(sysdate-1) unless you have a functional-index on SURGERY_DATE.
The query above will use a normal index on SURGERY_DATE if present, stats are up to date and the datadistribution is favourable.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search