?
Solved

Sort records that are less than 2

Posted on 2008-06-24
10
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

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…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 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