Solved

SQL Select on a Select with criteria

Posted on 2013-05-26
10
237 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

707 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

20 Experts available now in Live!

Get 1:1 Help Now