Solved

Sort records that are less than 2

Posted on 2008-06-24
10
184 Views
Last Modified: 2010-03-20
In what way can I sort / pull records that are less than or equals to 2" from a query shown below.

SELECT tblW.AppID, tblW.PermitNo, tblW.STypeID, tblW.GenStatus, tblW.ConnSizeID
FROM tblW
WHERE (((tblW.STypeID)="DM") AND ((tblW.GenStatus)="Application" Or (tblW.GenStatus)="NoPermit") AND ((tblW.ConnSizeID)<="2"));
'***********

Currently the records sort more records that are less than or equals to 2:

e.g:
AppID      PermitNo      STypeID      GenStatus      ConnSizeID
2      111111      DM      NoPermit      1/2
3      555555      DM      Application      1-1/4
5      212112      DM      NoPermit      2
6      652142      DM      NoPermit      12 x 3         '<--- This should not be sorted
9      251424      DM      Application      1-1/4
11      121212      DM      NoPermit      12 x 5          '<--- This should not be sorted
'***************

I also created an additional 3 column table "tblConnSize" in a joint with the SQL - but it did not work
ConnSizeID      ConnSize      ConnSizeType
1      5/8                        0.625
2      1/2                        0.5
3      3/4                        0.75
4      1                                 0.9
5      1-1/4                        1.25
6      1-1/2                        1.5
7      2                                 2
8      2-1/2                       2.5
9      3                                 3
10      4                                 4
' ...............................................................
' ...............................................................
15      6 x 2                      17
16      6 x 3                      18
17      6 x 4                      19
18      8 x 3                      20
19      8 x 4                      21
20      8 x 6                      22
' .............................................................
' .............................................................
25      12 x 3                     27
26      12 x 4                     28
27      12 x 6                     29
28      12 x 8                     30
0
Comment
Question by:billcute
  • 6
  • 3
10 Comments
 
LVL 7

Expert Comment

by:Chrisedebo
ID: 21855150
This should do it.
SELECT tblW.AppID, tblW.PermitNo, tblW.STypeID, tblW.GenStatus, tblW.ConnSizeID

FROM tblW inner join tblConnSize on tblw.connsizeid = tblconnsize.connsize

WHERE (((tblW.STypeID)="DM") AND ((tblW.GenStatus)="Application" Or (tblW.GenStatus)="NoPermit") AND ((tblW.ConnSizeID)<="2"))

Order by tblConnSize.connsizetype

Open in new window

0
 
LVL 7

Accepted Solution

by:
Chrisedebo earned 500 total points
ID: 21855161
when you say sort? do you mean select?

try this one:
SELECT tblW.AppID, tblW.PermitNo, tblW.STypeID, tblW.GenStatus, tblW.ConnSizeID

FROM tblW inner join tblConnSize on tblw.connsizeid = tblconnsize.connsize

WHERE (((tblW.STypeID)="DM") AND ((tblW.GenStatus)="Application" Or (tblW.GenStatus)="NoPermit") AND ((tblConnSize.connsizetype)<=2))

Open in new window

0
 
LVL 2

Expert Comment

by:sqd5597
ID: 21855253
Hi,

I think you were on the right track, but maybe had the syntax slightly wrong:
First, in your table tblConnSize I would rename the columns as:
   ConnID, ConnSizeID, ConnSizeType

This will prevent confusion with your other table column names.

Next try the following:

SELECT tblW.AppID, tblW.PermitNo, tblW.STypeID, tblW.GenStatus, tblConnSize.ConnID
FROM tblW left outer join tblConnSize
 on tblW.ConnSizeID = tblConnSize.ConnSizeID
WHERE (((tblW.STypeID)="DM") AND ((tblW.GenStatus)="Application" Or (tblW.GenStatus)="NoPermit") AND ((tblConnSize.ConnID)<="2"));

This should join the tables and allow you to sort the records you want.

Hope this helps
0
 
LVL 4

Author Comment

by:billcute
ID: 21855281
Thanks
0
 
LVL 7

Expert Comment

by:Chrisedebo
ID: 21855326
No Problem....

if you have what you need close the question and assign the points :o)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 4

Author Comment

by:billcute
ID: 21855340
sqd5597:
I received an error:
"Datatype mismatch in criteria expression
0
 
LVL 4

Author Comment

by:billcute
ID: 21855343
Chrisedebo:

Your second suggestion works. Thanks
0
 
LVL 4

Author Comment

by:billcute
ID: 21864212
Experts:
Thanks for your assistance. I have got a new question for your assistance.

http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_23513928.html

Regards
Bill
0
 
LVL 4

Author Comment

by:billcute
ID: 21864237
0
 
LVL 4

Author Comment

by:billcute
ID: 21893445
sqd5597 / Chrisedebo:
I have created yet a new question and also uploaded a sample db under ID: 21881853 on the subject - as a followup to this particular post. Please click the link below to see it.

http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_23520469.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now