Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order By Not Working

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Any reason why my OrderBy isn't working. The OverallRankingScore is a numeric field but stills sorts my LeadID

Code:
SELECT      TOP 100 PERCENT dbo.Leads.*, LeadID AS LeadIDText, OutcomeID AS OutcomeIDText, OverallRankingScore AS OverallRankingScoreText, 
                        NextTaskTime AS NextTaskTimeText, StatusScore AS StatusScoreText, TelephoneScore AS TelephoneScoreText, 
                        LoanSizeScore AS LoanSizeScoreText, DateAddedScore AS DateAddedScoreText, LoanTypeScore AS LoanTypeScoreText, 
                        EquityScore AS EquityScoreText, SourceScore AS SourceScoreText, OutcomeLastModified AS OutcomeLastModifiedText
FROM          dbo.Leads
WHERE      (OutcomeID = 'Pending') OR
                        (OutcomeID = 'No Answer') OR
                        (OutcomeID = 'Engaged') OR
                        (OutcomeID = 'Future Business') OR
                        (OutcomeID = 'Waiting on Base Rate Moving') OR
                        (OutcomeID = 'Scheduled Call Unsuccessful')
ORDER BY ABS(OverallRankingScore) DESC
 
Try using OverallRankingScoreText

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Can you run this query and post the output here:

Code:
Select Table_Name, Column_Name, Data_Type 
From   Information_Schema.Columns
Where  Table_Name = 'Leads'
       And Column_Name = 'OverallRankingScore'

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I managed to get it working by changing

Code:
TOP 100 PERCENT

to

Code:
TOP 2147483647

Read somewhere there is a bug with SQL 2005. Automatically adds the TOP 100 PERCENT which then cancels any orderby
 
I think you are a little mistaken. There is not a bug with SQL2005. Microsoft never supported order by's in views. With SQL2000, people discovered that Top 100 percent was a workaround for doing something that is unsupported. This hack doesn't work in SQL2005, so people came up with another one.

Instead of hacking your views, you should apply an order by at the time you use the view. Ex:

Create View AnyViewName
As
Select ......


-----------------------------------

Select Column(s) From AnyViewName Order By ColumnX


My concern is that you are relying on another hack that may not work with future versions of SQL Server.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you for your advice. The query is actually makes up the recordsource for a form. (I am using access frontend)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top