tags:

views:

96

answers:

2

Can anyone think of a reason to do this:

SELECT * FROM TableA ORDER BY cast(cast(RealColumnA as nvarchar(50))as float) --where RealColumnA is defined as real in the table

A former developer of mine insisted this was necessary to get reals to sort correctly. Can anyone think of a reason that may be true?

The cast in the orderby clause is a big performance killer. But I need to be sure it is not necessary before I remove it.

+5  A: 

Remove it. ORDER BY is what you expect it to be. And it certainly would be a performance killer.

Rule #1 about SQL. Question (and test) all your (and other peoples') assumptions. (Especially weird ones like this.)

le dorfier
A: 

This makes no sense. Especially with the CAST right back.

The only thing I could see is if you are storing non-float information in a float and want it sorted asciibetically. I guess you might want this:

1
10
11
12
2
3
4
5
6
7
8
9

But usually when that kind of storage optimization is done (like SSN or a phone number stored in an int, say), there is implicit padding assumed on the left which means that any expected sort is really the same as the normal numerical sort.

Cade Roux