Re: Nested select



"John" <John@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E00259AC-FF4E-44D6-8730-5800CFDAC22A@xxxxxxxxxxxxxxxx
Can you tell me whats wrong with this query?

select count(*) as CountedOrders
from
(
select distinct [order]
from [OrdersTable]
where
[Customer]='100000' and
[Order Date] between '01/01/2005' and '31/12/2005'
)

It runs perfect in MS Access but not in MS SQL-Server.

I need to create a stored procedure that returns the number of orders from
a
specific customer on a specific period.

Thanks in advance for your help.


SQL requires an alias for the derived table. Also ORDER has to be delimited
because it's a keyword (and therefore not a good choice for a column name).
It's also good practice to use a locale-independent date format like I have
done below.

SELECT COUNT(*) AS countedorders
FROM
(SELECT DISTINCT [order]
FROM OrdersTable
WHERE customer='100000'
AND [order date] BETWEEN '20050101' AND '20051231'
) AS T ;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--


.



Relevant Pages

  • Re: Put database on Internet
    ... > Once you will be able to connect to MSDE or to SQL-Server, ... > and ADP in the same time as frontends to your database. ... >> will be able to serve as SQL server. ...
    (microsoft.public.access.dataaccess.pages)
  • Re: Problem using SP as record source with Access2002 & SQL Server 7
    ... you shouldn't use the prefix sp_ for your stored procedures. ... SQL-Server Profiler; as you will see what ADP is trying to do when inserting ... > whole WHERE clause which is using them. ... > working with SQL Server 7, ...
    (microsoft.public.access.adp.sqlserver)
  • Re: A97 to SQL?
    ... The access/JET back-end is on the same LAN that your SQL-Server would be. ... You could migrate your data to a SQL-Server back-end, and link to your data there. ... Currently I am regularly adding little enhancements, new reports, etc etc, to the A97 mdb FE, and it's very useful that I can do this. ... I know nothing about SQL server, and am unlikely to be able to find the time to get into it. ...
    (microsoft.public.access.conversion)
  • Re: SSIS Datenkonvertierung
    ... Express-Edition) und hab die Informationen aus dem SQL-Server Management ... Microsoft Analysis Services-Clienttools 2005.090.1399.00 ... Services, das Management Studio, SQL-Server Analysis Services. ... Welche Version om SQL Server 2005 hast Du? ...
    (microsoft.public.de.sqlserver)
  • Query performance MS-Access vs. SQL-server 2000
    ... I am evaluating SQL server and therefore I made a benchmark comparing the ... search speed between Access and SQL-Server. ... The results of this benchmark are so strange and surprising, ... Dim Test_DB As DAO.Recordset, DB As Database ...
    (microsoft.public.sqlserver.programming)