Advertisement

05.08.2008 at 09:53PM PDT, ID: 23388462 | Points: 125
[x]
Attachment Details
Speed Up Cross tab Query In MS-ACCESS
Hi,
I am having access data given in input.xls format and i am using cross tab query to get output in form of output.xls.I am using query given below.Its working fine but taking time to execute.So,can anyone tell me how to modify query to get faster result.

Query:

TRANSFORM Last(rate) AS sumRating
SELECT symbol
FROM (SELECT Time,Rate,Symbol,
IIF(Time>=#10:00:00 AM# and Time<#11:00:00 AM#,IIF(Time<#10:10:00 AM#,'10:00:00-10:10:00',
       IIF(Time<#10:20:00 AM#,'10:10:01-10:20:00',
       IIF(Time<#10:30:00 AM#,'10:20:01-10:30:00',
       IIF(Time<#10:40:00 AM#,'10:30:01-10:40:00'
      ,IIF( time<#10:50:00 AM#,'10:40:01-10:50:00','10:50:01-11:00:00')
)))),
IIF(Time>=#11:00:00 AM# and Time<#12:00:00 PM#,IIF(Time<#11:10:00 AM#,'11:00:01-11:10:00',
       IIF(Time<#11:20:00 AM#,'11:10:01-11:20:00',
       IIF(Time<#11:30:00 AM#,'11:20:01-11:30:00',
       IIF(Time<#11:40:00 AM#,'11:30:01-11:40:00'
      ,IIF( time<#11:50:00 AM#,'11:40:01-11:50:00','11:50:01-12:00:00')
))))  
,IIF(Time>=#12:00:00 PM# and Time<#1:00:00 PM#,IIF(Time<#12:10:00 PM#,'12:00:01-12:10:00',
       IIF( Time<#12:20:00 PM#,'12:10:01-12:20:00',
       IIF(Time<#12:30:00 PM#,'12:20:01-12:30:00',
       IIF( Time<#12:40:00 PM#,'12:30:01-12:40:00'
      ,IIF( time<#12:50:00 PM#,'12:40:01-12:50:00','12:50:01-1:00:00')
))))
,IIF(Time>=#1:00:00 PM# and Time<#2:00:00 PM#,IIF( Time<#1:10:00 PM#,'1:00:01-1:10:00',
       IIF( Time<#1:20:00 PM#,'1:10:01-1:20:00',
       IIF( Time<#1:30:00 PM#,'1:20:01-12:30:00',
       IIF( Time<#1:40:00 PM#,'1:30:01-1:40:00'
      ,IIF( time<#1:50:00 PM#,'1:40:01-1:50:00','1:50:01-2:00:00')
))))
,IIF(Time>=#2:00:00 PM# and Time<#3:00:00 PM#,IIF(Time<#2:10:00 PM#,'2:00:01-12:10:00',
       IIF(Time<#2:20:00 PM#,'2:10:01-2:20:00',
       IIF(Time<#2:30:00 PM#,'2:20:01-2:30:00',
       IIF(Time<#2:40:00 PM#,'2:30:01-2:40:00'
      ,IIF( time<#2:50:00 PM#,'2:40:01-2:50:00','2:50:01-3:00:00')
))))
,IIF(Time>=#3:00:00 PM#,IIF( Time<#3:10:00 PM#,'3:00:01-3:10:00',
       IIF(Time<#3:20:00 PM#,'3:10:01-3:20:00',
       IIF(Time<#3:30:00 PM#,'3:20:01-3:30:00',
       IIF( Time<#3:40:00 PM#,'3:30:01-3:40:00'
      ,IIF( time<#3:50:00 PM#,'3:40:01-3:50:00')
))))
,'NONE'))))))As period from  broadcast where  symbol='TCS' or symbol='DLF' or symbol='SUMMIT'
)
GROUP BY symbol
PIVOT Period;

I want to display lastest rate for every script on interval of 10 minutes.







Attachments:
 
Input Access data for query
 
 
Required Output Format
 
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: orazen11
Question Asked On: 05.08.2008
Participating Experts: 2
Points: 125
Views: 0
Translate:
Loading Advertisement...
05.08.2008 at 11:21PM PDT, ID: 21530703

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 11:41PM PDT, ID: 21530757

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 11:44PM PDT, ID: 21530768

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 01:54AM PDT, ID: 21531191

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 02:33AM PDT, ID: 21531323

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.09.2008 at 03:27AM PDT, ID: 21531493

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.08.2008 at 11:21PM PDT, ID: 21530703

Rank: Wizard

Use a function to get the time interval:

Function tmIntvl(vtime)
Dim hr
Dim min
vtmntval = "NONE
if hr<10 or hr>=16 then exit function

hr = Hour(vtime)
min = (Minute(vtime) \ 10) * 10
tmIntvl = TimeSerial(hr, min, 1) & " - " & TimeSerial(hr, min + 10, 0)
End Function

Use
 tmIntvl([Time])  as period
 instead of your IIF
 
05.08.2008 at 11:41PM PDT, ID: 21530757

IIF is not taking time.........i tried to run only inner query where i am using IIF,its not taking much time.Cross tab query is taking much time........i think bcas number of columns are more in crosstab query
its taking time
 
05.08.2008 at 11:44PM PDT, ID: 21530768
and one more thing while i am using excel vba to get result from Ms-Access ,i am not able to receive column name along with data?Do you have any idea about it
 
05.09.2008 at 01:54AM PDT, ID: 21531191

Rank: Wizard

This query gives you basically the same answers:

    TRANSFORM Last(B.Rate)
    SELECT B.Symbol
    FROM broadcast AS B
    GROUP BY B.Symbol
    PIVOT CDate(Int(B.Time*144)/144);

That is, no answer at all, because Last() does not what you expect it to do. Last gives you any one value from the group -- the last encountered, and there is no syntax to specify which order you want to apply for the Last() function.

In other words, your query will get even slower by several orders of magnitude. For example, this is correct but terribly slow:

    SELECT B.Time, B.Symbol, B.Rate
    FROM broadcast AS B
    WHERE Not Exists (
        Select True From broadcast
        Where Symbol=B.Symbol
            And Time > B.Time And Time < (Int(B.Time*144)+1)/144
        );

Even with indexes on Symbol and Time, the calculation hurts the query, and nothing gets optimized. Instead, you can add a new field:

    Slice: Number, Integer; Indexed

And run this:

    UPDATE broadcast AS B SET B.Slice = Int(B.Time*144);

If needed, the equivalent time is: CDate(Slice/144) to CDate((Slice+1)/144). With all three indexes (on Symbol, Slice, and Time), this is reasonably fast:

    SELECT B.Time, B.Slice, B.Symbol, B.Rate
    FROM broadcast AS B
    WHERE Not Exists (
        Select True From broadcast
        Where Symbol=B.Symbol
            And Slice = B.Slice
            And Time > B.Time
        );

However, it uses a sub-query, so that it can't serve as source for a cross-tab. That's one of the annoying limitations of Jet SQL. You can now either use a make-table query and use the new table as source, or run a second update query, for the new field LastInS: Yes/No

    UPDATE broadcast SET LastInS = False;

    UPDATE broadcast AS B
    SET B.LastInS = True
    WHERE Not Exists (
        Select True From broadcast
        Where Symbol=B.Symbol
            And Slice = B.Slice
            And Time > B.Time
        );

LastInS indicates which records we want to see (113 among the 8888 you showed us). And now we have a fast cross-tab, for example:

    TRANSFORM First(B.Rate)
    SELECT B.Symbol
    FROM broadcast AS B
    WHERE B.LastInS
    GROUP BY B.Symbol
    PIVOT CDate(B.Slice/144) & '-' & CDate((B.Slice+1)/144);

or (looks better and is even faster)

    TRANSFORM First(B.Rate)
    SELECT CDate(B.Slice/144) AS [From], CDate((B.Slice+1)/144) AS [To]
    FROM broadcast AS B
    WHERE B.LastInS
    GROUP BY B.Slice
    PIVOT B.Symbol;

Cheers!
(°v°)
 
05.09.2008 at 02:33AM PDT, ID: 21531323
I am going to use this query after every 10-15 minutes .So, if i use make table query,so many tables will be generated.And then i am suppose to write query to delete table first,then again to create table  (Copy of source),then cross tab query on new table.Dont u think it will take much time?
 
05.09.2008 at 03:27AM PDT, ID: 21531493

Rank: Wizard

> after every 10-15 minutes

In that case, work only with the latest data. Keep track of the time you run the procedure and limit your queries to only the "time slices" that can still change.

If you added the fields Slice and LastInS, run the first update query for only "Slice Is Null" and the second for only "Slice >= (the corresponding number)". It will be even faster. But the update queries are already quite fast, and you probably tested the cross-tab: it's now almost instantaneous, isn't it?

Do not use the make-table query, as that would force you to regenerate the entire table every time, and it can't be faster than the update query.

(°v°)
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628