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

Wednesday, March 21, 2012

Error when field in ORDER BY does not match SELECT DISTINCT fields

This error crept up in SQL 2005 and does not appear in earlier versions of
SQL Server. The below code looks like:
SELECT DISTINCT 'Test' As TestName, ...
FROM ...
ORDER BY 'Test'
I had to change the ORDER BY to the alias TestName to get is to compile and
run in SQL2005. Is there a SQL command I can run to prior to adding my view
to prevent these messages? Or do I lump it and change all occurrences to us
e
the alias in the ORDER BY?
Thanks for your help,
TomOn Mon, 20 Mar 2006 10:27:30 -0800, Tom Kelley <Tom
Kelley@.discussions.microsoft.com> wrote:

>This error crept up in SQL 2005 and does not appear in earlier versions of
>SQL Server. The below code looks like:
>SELECT DISTINCT 'Test' As TestName, ...
>FROM ...
>ORDER BY 'Test'
>I had to change the ORDER BY to the alias TestName to get is to compile and
>run in SQL2005.
Hi Tom,
SQL Server 2000 was very forgiving WRT what it allowed you to put in an
ORDER BY clause. That had some great advantages, but some divantages
as well, since it allowed you to write rather ambiguous things, and it
would often interpret it different from what you meant. For instance, if
you still have access to a SQL Server 2000 installation, run the code
below and try to explain the results.
CREATE TABLE Persons
(FirstName varchar(20) NOT NULL,
LastName varchar(20) NOT NULL
)
go
INSERT INTO Persons (FirstName, LastName)
SELECT 'Hugo', 'Kornelis'
UNION ALL
SELECT 'Tom', 'Kelly'
go
SELECT LastName
FROM Persons
ORDER BY FirstName
go
SELECT LastName AS FirstName, FirstName AS LastName
FROM Persons
ORDER BY FirstName
go
SELECT LastName AS FirstName
FROM Persons
ORDER BY FirstName
go
SELECT LastName AS FirstName
FROM Persons
ORDER BY Persons.FirstName
go
SELECT LastName AS FirstName
FROM Persons
ORDER BY FirstName + ''
go
DROP TABLE Persons
go
Anyway, SQL Server 2005 is more strict (though not nearly as strict as
what the official ANSI standards for SQL allow <g> ). You might have to
change some ORDER BY clauses.

> Is there a SQL command I can run to prior to adding my view
>to prevent these messages? Or do I lump it and change all occurrences to u
se
>the alias in the ORDER BY?
The ORDER BY clause doesn't only accept the alias - it accepts column
names and expressions as well (though apparently not an "expression"
that is a string constant).
Though I personally fail to see ANY reason why you would want to include
a constant value in your ORDER BY list.
Hugo Kornelis, SQL Server MVPsql

Friday, February 17, 2012

Error Sorting

I need the results of a view sorted by date. When the order by date is added
to the view I get the following error from SQL/ODBC SQL Driver:
"cannot sort a row of size 8813, which is greater than the allowable maximum
of 8094"
Is there a way around this?
Thanks
Niles wrote:
> I need the results of a view sorted by date. When the order by date
> is added to the view I get the following error from SQL/ODBC SQL
> Driver: "cannot sort a row of size 8813, which is greater than the
> allowable maximum of 8094"
> Is there a way around this?
> Thanks
You can cut down the result set row size. Why is the row so large?
David Gugick
Imceda Software
www.imceda.com
|||I reduced the number of columns returned and it works fine now. Why is the
number of columns a factor here?
Thanks
"David Gugick" wrote:

> Niles wrote:
> You can cut down the result set row size. Why is the row so large?
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>
|||Niles wrote:
> I reduced the number of columns returned and it works fine now. Why
> is the number of columns a factor here?
>
8060 is the maximum row size for SQL Server. It's not so much the number
of columns, but the total byte size of all columns in a row. While SQL
Server will allow you to create a table with varchar type columns that
could potentially add up to more than 8060 bytes, you do get a warning
when the table is created. If at any point you change data in a row or
attempt to insert more than 8060 bytes in a row, you get an error.
Since you didn't post any SQL, I can only assume that your table is as
described above, or your columns in the query from multiple tables are
large enough that you're reaching the SQL Server limit.
If you are dealing with a large table or a large table is responsible
for most of the row size, I would encourage you to consider redesigning
the table. Large row sizes mean very low page density. This leads to
excessive page reading on some queries and a general slowdown on the
server when the table is accessed. If you can, you could put some of
that large variable data in a text/ntext column or possibly in another
table.
If you want other suggestions, post your DDL and SQL.
David Gugick
Imceda Software
www.imceda.com
|||In addition to the other posts:
You could try the ROBUST PLAN optimizer hint.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Niles" <Niles@.discussions.microsoft.com> wrote in message
news:D1591C68-5A0E-41A0-A453-C8D7957E5F47@.microsoft.com...
>I need the results of a view sorted by date. When the order by date is added
> to the view I get the following error from SQL/ODBC SQL Driver:
> "cannot sort a row of size 8813, which is greater than the allowable maximum
> of 8094"
> Is there a way around this?
> Thanks

Error Sorting

I need the results of a view sorted by date. When the order by date is adde
d
to the view I get the following error from SQL/ODBC SQL Driver:
"cannot sort a row of size 8813, which is greater than the allowable maximum
of 8094"
Is there a way around this?
ThanksNiles wrote:
> I need the results of a view sorted by date. When the order by date
> is added to the view I get the following error from SQL/ODBC SQL
> Driver: "cannot sort a row of size 8813, which is greater than the
> allowable maximum of 8094"
> Is there a way around this?
> Thanks
You can cut down the result set row size. Why is the row so large?
David Gugick
Imceda Software
www.imceda.com|||I reduced the number of columns returned and it works fine now. Why is the
number of columns a factor here?
Thanks
"David Gugick" wrote:

> Niles wrote:
> You can cut down the result set row size. Why is the row so large?
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>|||Niles wrote:
> I reduced the number of columns returned and it works fine now. Why
> is the number of columns a factor here?
>
8060 is the maximum row size for SQL Server. It's not so much the number
of columns, but the total byte size of all columns in a row. While SQL
Server will allow you to create a table with varchar type columns that
could potentially add up to more than 8060 bytes, you do get a warning
when the table is created. If at any point you change data in a row or
attempt to insert more than 8060 bytes in a row, you get an error.
Since you didn't post any SQL, I can only assume that your table is as
described above, or your columns in the query from multiple tables are
large enough that you're reaching the SQL Server limit.
If you are dealing with a large table or a large table is responsible
for most of the row size, I would encourage you to consider redesigning
the table. Large row sizes mean very low page density. This leads to
excessive page reading on some queries and a general slowdown on the
server when the table is accessed. If you can, you could put some of
that large variable data in a text/ntext column or possibly in another
table.
If you want other suggestions, post your DDL and SQL.
David Gugick
Imceda Software
www.imceda.com|||In addition to the other posts:
You could try the ROBUST PLAN optimizer hint.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Niles" <Niles@.discussions.microsoft.com> wrote in message
news:D1591C68-5A0E-41A0-A453-C8D7957E5F47@.microsoft.com...
>I need the results of a view sorted by date. When the order by date is add
ed
> to the view I get the following error from SQL/ODBC SQL Driver:
> "cannot sort a row of size 8813, which is greater than the allowable maxim
um
> of 8094"
> Is there a way around this?
> Thanks

Error Sorting

I need the results of a view sorted by date. When the order by date is added
to the view I get the following error from SQL/ODBC SQL Driver:
"cannot sort a row of size 8813, which is greater than the allowable maximum
of 8094"
Is there a way around this?
ThanksNiles wrote:
> I need the results of a view sorted by date. When the order by date
> is added to the view I get the following error from SQL/ODBC SQL
> Driver: "cannot sort a row of size 8813, which is greater than the
> allowable maximum of 8094"
> Is there a way around this?
> Thanks
You can cut down the result set row size. Why is the row so large?
David Gugick
Imceda Software
www.imceda.com|||I reduced the number of columns returned and it works fine now. Why is the
number of columns a factor here?
Thanks
"David Gugick" wrote:
> Niles wrote:
> > I need the results of a view sorted by date. When the order by date
> > is added to the view I get the following error from SQL/ODBC SQL
> > Driver: "cannot sort a row of size 8813, which is greater than the
> > allowable maximum of 8094"
> > Is there a way around this?
> >
> > Thanks
> You can cut down the result set row size. Why is the row so large?
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>|||Niles wrote:
> I reduced the number of columns returned and it works fine now. Why
> is the number of columns a factor here?
>
8060 is the maximum row size for SQL Server. It's not so much the number
of columns, but the total byte size of all columns in a row. While SQL
Server will allow you to create a table with varchar type columns that
could potentially add up to more than 8060 bytes, you do get a warning
when the table is created. If at any point you change data in a row or
attempt to insert more than 8060 bytes in a row, you get an error.
Since you didn't post any SQL, I can only assume that your table is as
described above, or your columns in the query from multiple tables are
large enough that you're reaching the SQL Server limit.
If you are dealing with a large table or a large table is responsible
for most of the row size, I would encourage you to consider redesigning
the table. Large row sizes mean very low page density. This leads to
excessive page reading on some queries and a general slowdown on the
server when the table is accessed. If you can, you could put some of
that large variable data in a text/ntext column or possibly in another
table.
If you want other suggestions, post your DDL and SQL.
--
David Gugick
Imceda Software
www.imceda.com|||In addition to the other posts:
You could try the ROBUST PLAN optimizer hint.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Niles" <Niles@.discussions.microsoft.com> wrote in message
news:D1591C68-5A0E-41A0-A453-C8D7957E5F47@.microsoft.com...
>I need the results of a view sorted by date. When the order by date is added
> to the view I get the following error from SQL/ODBC SQL Driver:
> "cannot sort a row of size 8813, which is greater than the allowable maximum
> of 8094"
> Is there a way around this?
> Thanks