Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Group by - part of a field
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Group by - part of a field

 Post Reply Post Reply
Author
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Topic: Group by - part of a field
    Posted: 02 April 2003 at 2:37pm
Part of a statement is...

strSQL = strSQL & "GROUP BY tblResults.Car_Number "

For reasons too complicated to report here, Car_Number is a decimal number with 2dp.

Under one condition, I want to "Group By" the exact number (i.e., as per the above code); otherwise I want to group by Car_Number trimmed to 1dp.

Does there exist a function that would let me write:

strSQL = strSQL & "GROUP BY (function to trim to 1dp)tblResults.Car_Number "

?

If not, I'll have to come up with something else, but if possible the above would provide a neat solution to my particular problem.

Ta
www.pedalcars.info

The most fun on four wheels

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 02 April 2003 at 3:35pm
If I understand right the car number is something like 5.32 and you want to group by that number but sometimes you want to just by 5.3 ? as there are cars called 5.31  5.32  5.33 and so forth? Let me know if that is what you want to do!
Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 02 April 2003 at 4:28pm
Bang on, yes.
www.pedalcars.info

The most fun on four wheels

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 02 April 2003 at 5:11pm
Well you got a little problem there I think. If you'd use SQL Server you could just execute something like
select carid from table
group by left(carid,3)
this unfortunately does not work in access though. I would create an extra field in access and just enter the part you need for that grouping or create a temp table, select everything into there using left  (assuming the carid is always below 10 otherwise use another function) and then query that temp table. Let me know if you get stuck doing that... 
Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 03 April 2003 at 2:38am
Thanks for the help. It occurred late last night that even if I could do what I wanted, it would only have given me a partial solution to what I wanted to do.

Thus I now have an additional table; so far this seems to be working and able to cope with whatever demands I'm making of it.

Thanks again.

Edit additional: It also occurs that the left(carid,3) would stumble on cars with double-figure numbers. I thought I was asking a lot...

Edited by pedalcars
www.pedalcars.info

The most fun on four wheels

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 03 April 2003 at 7:24am
That is why I said if there are double digitnumber in there you shoulduse seomthing like formatnumber() or so.
Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 03 April 2003 at 8:41am
Sorry, missed that bit first time round. D'oh!
www.pedalcars.info

The most fun on four wheels

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.