Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL sorting
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL sorting

 Post Reply Post Reply
Author
Boecky View Drop Down
Groupie
Groupie
Avatar

Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boecky Quote  Post ReplyReply Direct Link To This Post Topic: SQL sorting
    Posted: 27 July 2003 at 8:27am

I just want to know if this is the best way to do this. It's for sorting a list with 2 parameters (strSort and strType). Or I use both, only strSort or only strType or Nothing. Any other suggestions pls let me know.

If strSort = "" AND strType = "" Then
 rsList.Source = "SELECT * FROM tblList"
 ElseIf strSort <> "" AND strType = "" Then
 rsList.Source = "SELECT * FROM tblList ORDER BY " & strSort & " ASC"
 ElseIf strSort = "" AND strType <> "" Then
 rsList.Source = "SELECT * FROM tblList WHERE Type=" & strType2 & ""
 ElseIf strSort <> "" AND strType <> "" Then
 rsList.Source = "SELECT * FROM tblList WHERE Type=" & strType2 & " ORDER BY " & strSort & " ASC"
End If

Back to Top
Boecky View Drop Down
Groupie
Groupie
Avatar

Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boecky Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2003 at 2:40am
nobody can gives a meaning?
Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2003 at 3:27am

Personally I would do it as follows:

strSQL = "Select * From tblList "
If strType <> "" Then
  strSQL = strSQL & "Where Type=" & strType2 & " "
End If
If strSort <> "" Then
  strSQL = strSQL & "Order By " & strSort & " Asc "
End If
rsList.Source = strSQL

Hope this helps,
Blair

Webmaster, The Plane Gallery
Greetings From Christchurch
Back to Top
Boecky View Drop Down
Groupie
Groupie
Avatar

Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
Post Options Post Options   Thanks (0) Thanks(0)   Quote Boecky Quote  Post ReplyReply Direct Link To This Post Posted: 30 July 2003 at 9:16am
Ok tkx, but is this faster or more 'optimized' then an 'ElseIf'?
Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post Posted: 30 July 2003 at 4:52pm

Don't know, they're both using If...ElseIf blocks, so they should be about the same. The main reason I do it that way is because it is easier, and makes neater code, than writing all the combinations yourself. It is not so noticeable with just two options, but if you have four options, then there are (I think) 12 different combinations.

Blair

Webmaster, The Plane Gallery
Greetings From Christchurch
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.