Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2003, 05:33 PM
Registered User
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default complex SQL using JET-SQL

hi all,

ok this is the scenario....

I have a table containing roughly 2,500,000 records of mixed record types. e.g.

440, 123456, peoples avenue, ab12 2lx
441, abc, 19970801
451, _A, metering point, available
460, EELLC, 19970901
440, 123457, an address road, bc13 4vx
441, abd, 19980802
451, _A, metering point, occupied
460, EELLC, 19980901
440 ....... [and so on ...]


basically I have imported this file into ACCESS 2000 and need to seperate each record type (i.e. 451, 441 etc...) to their corresponding 440 record

The way I thought to doing this is to add an additional field called 'sortKey'. Whereby for every 440 record sortKey = sortKey + 1

whereby the output would look like this:

440, 123456, peoples avenue, ab12 2lx, 1 (sortKey)
441, abc, 19970801, 1
451, _A, metering point, available, 1
460, EELLC, 19970901, 1
440, 123457, an address road, bc13 4vx, 2 (sortKey + 1)
441, abd, 19980802, 2
451, _A, metering point, occupied, 2
460, EELLC, 19980901, 2


Now, I have managed to achieve this writing a Vb module within ACCESS however ACCESS will only run my Vb code providing the total number of records is no more than 170,000 otherwise I get the error 'Invalid Argument'.

what I have noticed is that Access appears to function with no problems with SQL... therefore.. I'm trying to write an SQL that will populate the sortKey field.

the kind of SQL I was looking at was along the lines of using a CASE WHEN statement however I am having some serious syntax probs coz its JET - SQL within ACCESS.

SELECT a.Field1, a.sortKey(CASE a.Field1 WHEN 440 THEN count+1 ELSE count END)
FROM data204 AS a;

can anyone help??
thanks

Andy

 
Old October 2nd, 2003, 09:28 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are you trying to acomplish with this exactly.



Sal
 
Old October 2nd, 2003, 09:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create the following VB macro function in Access:

Code:
Public Function YourSortKeyFunction(ByVal intField As Integer) As Long

Static lngSortKey As Long

    If intField = 440 Then lngSortKey = lngSortKey + 1
    YourSortKeyFunction = lngSortKey

End Function
Then use the function in the following SQL statement:

Code:
SELECT a.Field1, YourSortkeyFunction(a.Field1) AS SortKey
FROM data204 AS a;
I think that this should be able to cope with 2,500,000 rows, but I am not sure. It's worth a go though.

Regards
Owain Williams
 
Old October 2nd, 2003, 10:01 AM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you trying to do this just to sort your records?
What is the requirement for this. You may be going about it the hard way.
If all you need is to use it to sort your records, you may be able to use an autonumber field in conjunction with your 440,441,442 field to sort permanently, easing the load on your database permanently.



Sal





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL-Union works in Access but not in Jet tonatwinemaker Access ASP 5 February 20th, 2006 04:37 PM
jet sql query help connect2sandep Access 4 October 28th, 2005 02:16 PM
Converting a Jet query to SQL that uses a function Mitch SQL Server 2000 5 February 28th, 2005 12:33 PM
HELP!!! Jet SQL: Error (80040e14) Coldendus Access VBA 3 December 14th, 2004 08:12 PM
Migrating from Jet to SQL Ray Pinnegar Access 2 October 8th, 2004 04:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.