Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

TSQL-Order by Expand / Collapse
Author
Message
Posted Saturday, July 13, 2013 3:25 PM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: 2 days ago @ 7:49 AM
Points: 608, Visits: 1,027
Comments posted to this topic are about the item TSQL-Order by

Pramod
SQL Server DBA | MCSA SQL Server 2012

in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
Post #1473322
Posted Sunday, July 14, 2013 10:58 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 1:41 AM
Points: 451, Visits: 578
easy one...!!!
Post #1473444
Posted Sunday, July 14, 2013 11:07 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, June 24, 2014 6:38 PM
Points: 1,371, Visits: 1,560
Easy one for Monday morning
Thanks Pramod!


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1473447
Posted Sunday, July 14, 2013 11:25 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:34 AM
Points: 1,888, Visits: 2,326
Lokesh Vij (7/14/2013)
Easy one for Monday morning
Thanks Pramod!

+1



_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1473450
Posted Sunday, July 14, 2013 11:32 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:34 AM
Points: 1,888, Visits: 2,326
When I checked the BOL i found that there is a line stating:
If a table name is aliased in the FROM clause, only the alias name can be used to qualify its columns in the ORDER BY clause.
I did some modification in the query and try to run following scenarios and these all are working.
select a ss from test t
order by ss

select t.a ss from test t
order by a

select a from test t
order by a

Can anyone tell me what does that BOL line means?



_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1473452
Posted Sunday, July 14, 2013 11:46 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
Thanks for start Monday with easy one



Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1473454
Posted Sunday, July 14, 2013 11:58 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
kapil_kk (7/14/2013)
When I checked the BOL i found that there is a line stating:
If a table name is aliased in the FROM clause, only the alias name can be used to qualify its columns in the ORDER BY clause.
I did some modification in the query and try to run following scenarios and these all are working.
select a ss from test t
order by ss

select t.a ss from test t
order by a

select a from test t
order by a

Can anyone tell me what does that BOL line means?


According to BOl, If you have given a alias name to column name then you can not use column name in order by clause.

the 2nd statement should give error like "invalid column name "a" ", but it doesn't. I am also looking for reason why 2nd T-sql code execute successfully.




Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1473456
Posted Monday, July 15, 2013 12:58 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Yesterday @ 6:15 AM
Points: 638, Visits: 661
You haven't read it carefully. It says: "If a table name is aliased, only the alias name can be used to qualify its columns in the ORDER BY clause."

So this will not work:

select a from test t
order by test.a



_______________________________________________
www.sql-kefalo.net (SQL Server saveti, ideje, fazoni i fore)
Post #1473480
Posted Monday, July 15, 2013 1:14 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 10:26 AM
Points: 13,359, Visits: 10,223
Interesting question for a Monday



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1473493
Posted Monday, July 15, 2013 1:48 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, July 4, 2014 9:03 AM
Points: 1,415, Visits: 796
Easy easy easy.

Nice start to the week.
Post #1473512
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse