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: Yesterday @ 7:51 AM
Points: 1,945, Visits: 2,864
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 @ 8:33 AM
Points: 2,469, Visits: 2,346
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: Tuesday, July 29, 2014 4:57 AM
Points: 190, Visits: 393
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: Wednesday, June 11, 2014 5:49 AM
Points: 8, Visits: 99
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: 2 days ago @ 6:22 AM
Points: 2,684, Visits: 2,435
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 4, 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
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 9:39 AM
Points: 80, Visits: 719
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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 10:40 AM
Points: 1,606, Visits: 4,599
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.
Post #1195679
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse