Solved

SQL Select on a Select with criteria

Posted on 2013-05-26
10
244 Views
Last Modified: 2013-05-31
Hi

I have a number of queries that I have to select a date range on. The query below\
is SELECT [Transactions].* FROM [Transactions]) is one of these. What is wrong with my syntax below?


Select * From (SELECT [Transactions].* FROM [Transactions]) Where [Transaction Date] >'01 February 2013' AND [Transaction Date] <'26 May 2013'
0
Comment
Question by:murbro
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 8

Expert Comment

by:rpkhare
ID: 39197401
Please try below as inner query:
SELECT * FROM [Transactions]
WHERE [TransactionDate] BETWEEN
'2013-02-01' AND '2013-05-26'

Open in new window

0
 

Author Comment

by:murbro
ID: 39197478
Hi. Thanks but that doesn't help. I am trying to do a Select on a Select with criteria
0
 

Accepted Solution

by:
murbro earned 0 total points
ID: 39197479
Worked it out myself

Select * From (SELECT [Transactions].* FROM [Transactions]) As oAlias Where [Transaction Date] >'01 February 2013' AND [Transaction Date] <'26 May 2013'
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:murbro
ID: 39197496
I've requested that this question be closed as follows:

Accepted answer: 0 points for murbro's comment #a39197479

for the following reason:

worked it out myself
0
 
LVL 8

Expert Comment

by:rpkhare
ID: 39197497
A valid and more better way was suggested for the inner query.
0
 
LVL 8

Expert Comment

by:rpkhare
ID: 39197498
SELECT * FROM
(SELECT * FROM [Transactions]
WHERE [TransactionDate] BETWEEN
'2013-02-01' AND '2013-05-26') T

Open in new window

0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39197679
>I am trying to do a Select on a Select with criteria
Just for kicks and giggles, can you give us an English-only description of what you mean by 'Select on a Select'?
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39197680
Reason I ask is because if we're talking only one table, and you're not doing anything funky such as filtering on sum values, rank orders, pivot/unpivot, or time series, then a simple select should meet most needs, as was in the first comment.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39197803
I would agree with Jim, you do not need the sub query in this instance.

And I would recommend using a syntax other than BETWEEN when working with dates.

Where datefield  >= '2013-02-01' AND datefield < '2013-05-27'

This will ensure that if your datefield contains a time component you include all records that are attributed to 2013-05-26, not just those where the date value is '2013-05-26 00:00:00'
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

792 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