Showing posts with label order. Show all posts
Showing posts with label order. Show all posts

Friday, March 30, 2012

Query.

SELECT TOP 10 *
FROM (
SELECT TOP 60 *
FROM Patient
ORDER BY PA_VPatientID DESC
)
ORDER BY PA_VPatientID DESC
Error :-
Server: Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'ORDER'.
I did it through the following query
SELECT TOP 10 *
FROM (SELECT TOP 60 *
FROM Patient
ORDER BY PA_VPatientID DESC) a
ORDER BY PA_VPatientID
"Noor" <noor@.ngsol.com> wrote in message
news:eOrEnezXEHA.3044@.TK2MSFTNGP09.phx.gbl...
>
> SELECT TOP 10 *
> FROM (
> SELECT TOP 60 *
> FROM Patient
> ORDER BY PA_VPatientID DESC
> )
> ORDER BY PA_VPatientID DESC
>
> Error :-
> Server: Msg 156, Level 15, State 1, Line 5
> Incorrect syntax near the keyword 'ORDER'.
>
|||Why are you doing that? Simply using:
SELECT TOP 10 * FROM Patient ORDER BY PA_VPatientID DESC
would be more efficient.
Andrew J. Kelly SQL MVP
"Noor" <noor@.ngsol.com> wrote in message
news:eOrEnezXEHA.3044@.TK2MSFTNGP09.phx.gbl...
>
> SELECT TOP 10 *
> FROM (
> SELECT TOP 60 *
> FROM Patient
> ORDER BY PA_VPatientID DESC
> )
> ORDER BY PA_VPatientID DESC
>
> Error :-
> Server: Msg 156, Level 15, State 1, Line 5
> Incorrect syntax near the keyword 'ORDER'.
>

Tuesday, March 20, 2012

Query to list all tables does not work in SQL Server 2005

I am trying to execute and SQL Query in SQL Server 2005 in order to return
all tables.
Whenever I execute this query:
select table_name from information_schema.tables
I receive this error each time:
Invalid object name 'information_schema.tables'.
Does anyone know what is happening? This seems to be a pretty standard
query to return all tables from what I have read.
--TR
SQL Server Version Info:
Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) Mar 23 2007 16:28:52
Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT
5.1 (Build 2600: Service Pack 2)
Maybe you have case sensitive collation. Try this:
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
Also, the query below should give you the same info:
SELECT O.name AS table_name
FROM sys.objects AS O
WHERE O.type = 'U';
HTH,
Plamen Ratchev
http://www.SQLStudio.com
|||Is your database case sensitive? If so, you'll need to execute this query:
select table_name from INFORMATION_SCHEMA.TABLES
-Susan
"Ryan" wrote:

> I am trying to execute and SQL Query in SQL Server 2005 in order to return
> all tables.
> Whenever I execute this query:
> select table_name from information_schema.tables
> I receive this error each time:
> Invalid object name 'information_schema.tables'.
> Does anyone know what is happening? This seems to be a pretty standard
> query to return all tables from what I have read.
>
> --TR
> SQL Server Version Info:
> Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) Mar 23 2007 16:28:52
> Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT
> 5.1 (Build 2600: Service Pack 2)
>

Query to list all tables does not work in SQL Server 2005

I am trying to execute and SQL Query in SQL Server 2005 in order to return
all tables.
Whenever I execute this query:
select table_name from information_schema.tables
I receive this error each time:
Invalid object name 'information_schema.tables'.
Does anyone know what is happening? This seems to be a pretty standard
query to return all tables from what I have read.
--TR
SQL Server Version Info:
Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) Mar 23 2007 16:28:52
Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT
5.1 (Build 2600: Service Pack 2)Maybe you have case sensitive collation. Try this:
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
Also, the query below should give you the same info:
SELECT O.name AS table_name
FROM sys.objects AS O
WHERE O.type = 'U';
HTH,
Plamen Ratchev
http://www.SQLStudio.com|||Is your database case sensitive? If so, you'll need to execute this query:
select table_name from INFORMATION_SCHEMA.TABLES
-Susan
"Ryan" wrote:
> I am trying to execute and SQL Query in SQL Server 2005 in order to return
> all tables.
> Whenever I execute this query:
> select table_name from information_schema.tables
> I receive this error each time:
> Invalid object name 'information_schema.tables'.
> Does anyone know what is happening? This seems to be a pretty standard
> query to return all tables from what I have read.
>
> --TR
> SQL Server Version Info:
> Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) Mar 23 2007 16:28:52
> Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT
> 5.1 (Build 2600: Service Pack 2)
>