Solved

Sort records that are less than 2

Posted on 2008-06-24
10
187 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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