Solved

SQL Select on a Select with criteria

Posted on 2013-05-26
10
241 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

770 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