Solved

Sort records that are less than 2

Posted on 2008-06-24
10
185 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

16 Experts available now in Live!

Get 1:1 Help Now