Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 1st, 2012, 04:31 PM
Midway Midway is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 3 Midway User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 13 m 33 sec
Reputation Power: 0
SQL Server query to be convert it to Oracle 10g

DECLARE @MainTable TABLE (UniqueID INTEGER, Category VARCHAR(200), WeekDate DATETIME, VALUE INTEGER)

INSERT INTO @MainTable VALUES(123, 'Shirts', '10/07/2011', 5000)

INSERT INTO @MainTable VALUES(123, 'Shirts', '10/14/2011', 8000)

INSERT INTO @MainTable VALUES(124, 'Pants', '10/07/2011', 4000)

INSERT INTO @MainTable VALUES(125, 'Shorts', '10/14/2011', 8000)

INSERT INTO @MainTable VALUES(126, 'Shoes', '10/21/2011', 9000);

--select * from @MainTable;

WITH Dates AS

(

SELECT DISTINCT WeekDate FROM @MainTable
),

Categories AS (SELECT DISTINCT Category FROM @MainTable),

AllInfo AS (SELECT WeekDate, Category FROM Dates, Categories)

SELECT d.UniqueID, A.Category,d.Value, A.WeekDate
INTO #Results
FROM AllInfo A LEFT JOIN @MainTable d

ON d.WeekDate = A.weekDate AND A.Category = d.Category

ORDER BY A.Category, A.WeekDate

SELECT R.UniqueID, R.Category, COALESCE(R.VALUE, Cor.VALUE) AS VALUE, R.WeekDate
FROM #Results R
OUTER APPLY (SELECT TOP (1) Value FROM #Results R1 WHERE R1.Category = R.Category
AND R1.WeekDate <=R.WeekDate AND R1.Value IS NOT NULL ORDER BY WeekDate) Cor
ORDER BY R.Category, R.WeekDate

The query works with all the CTEs up to the last select statement. Oracle does not support the OUTER APPLY statement, would anybody know how should the last piece be written to make it work in Oracle?

Thanks very much for you help.

Reply With Quote
  #2  
Old February 1st, 2012, 04:48 PM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,701 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 4 Days 2 h 17 m 41 sec
Reputation Power: 284
What exactly does OUTER APPLY do?

Isn't that just a LEFT OUTER JOIN?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > SQL Server query to be convert it to Oracle 10g

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap