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»»»

Using TOP To Rank Columns In a Table Expand / Collapse
Author
Message
Posted Monday, October 24, 2011 10:28 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 26, 2013 12:38 PM
Points: 338, Visits: 449
Comments posted to this topic are about the item Using TOP To Rank Columns In a Table

Post #1195548
Posted Monday, October 24, 2011 11:10 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945, Visits: 2,782
Why did you encourage him? Sounds like time for re-education

Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1195554
Posted Tuesday, October 25, 2011 1:18 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 6:53 AM
Points: 2,393, Visits: 2,286
CELKO (10/24/2011)
Why did you encourage him? Sounds like time for re-education

I agree.
Post #1195570
Posted Tuesday, October 25, 2011 1:29 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, February 12, 2014 3:15 AM
Points: 189, Visits: 377
Regardless of whether or not this is a "bright idea", it's a little worrying that the developer did not know enough to approach the problem for themself, or have the nouse to research it.


Inflatable sailors never die, they gently deflate over time.

Post #1195572
Posted Tuesday, October 25, 2011 2:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 07, 2014 6:59 AM
Points: 7, Visits: 93
if was just a means to an end then just do a SELECT * FROM and dont bother with the schema extract.
Cringe, really bad a * but so.
Post #1195577
Posted Tuesday, October 25, 2011 2:06 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 4:32 AM
Points: 2,678, Visits: 2,394
What was the answer to the question 'why?'?
Post #1195579
Posted Tuesday, October 25, 2011 2:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 27, 2011 8:03 AM
Points: 5, Visits: 7
Excellent, removes the need for Cursors, and is very flexible to build up a totally dynamic Select clause that is very very useful indeed...

More like this please.....
Post #1195585
Posted Tuesday, October 25, 2011 4:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 04, 2014 9:12 AM
Points: 3, Visits: 45
For select dthe columns without remove last comma

SELECT TOP 10 @columnName = COALESCE(@columnName + ',' + QUOTENAME(COLUMN_NAME), QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @tableName
AND TABLE_SCHEMA = 'DBO'
ORDER BY ORDINAL_POSITION ASC
Post #1195600
Posted Tuesday, October 25, 2011 6:25 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 6:39 AM
Points: 73, Visits: 669
I've been coming to these forums long enough to know that Joe Celko was going to respond to this one. I recall Joe discussing the TOP clause in another forum long ago. Correct me if I'm wrong Joe, but TOP isn't to be trusted to pull the "first rows in a table" because tables don't store rows in any particular order. Is that what you were going for in your re-education reprimand? I've always felt it was a little misleading...it should have been called LIMIT or something like that because that's all it's really doing...limiting the result set.

IMHO.

Gabe
Post #1195670
Posted Tuesday, October 25, 2011 6:41 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: 2 days ago @ 12:40 PM
Points: 1,477, Visits: 4,281
CELKO (10/24/2011)
Why did you encourage him? Sounds like time for re-education

On a slow day, even the best of us may become so distracted by the challenge of solving some small puzzle that we forget to probe into why the puzzle was there to begin with.



"Winter Is Coming" - April 6, 2014
Post #1195679
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse