Solved

Sort records that are less than 2

Posted on 2008-06-24
10
186 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
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: 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

823 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