Pervasive 11 SQL custom order by

I wish to sort data based on the first 4 characters of field using Pervasive 11.

Tried case statement, left, substring, etc.

Any help?
Sheldon LivingstonConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike EghtebasDatabase and Application DeveloperCommented:
You just use

Order By FieldName

because it is first 4 characters of field (assuming from left)
Sheldon LivingstonConsultantAuthor Commented:
???

I'm looking for something like:

SELECT FIELDS1, FIELD2, FIELD3 FROM TABLE

ORDER BY
  CASE
    WHEN LEFT("PHASE",4) = 'HC.0' then '1'
    WHEN LEFT("PHASE",4) = 'HA.0' then '2'
    WHEN LEFT("PHASE",4) = 'AA.0' then '3'
    ELSE '5'
  END
Mike EghtebasDatabase and Application DeveloperCommented:
SELECT FIELDS1, FIELD2, FIELD3, PHASE FROM TABLE
Order By
CASE LEFT(PHASE,4) 
         WHEN 'HC.0' then '01'
         WHEN 'HA.0' then '02'
         WHEN 'AA.0' then '03'
         ELSE '04'
 END

Open in new window


Or
SELECT FIELDS1, FIELD2, FIELD3, PHASE, LEFT(PHASE,4) As SortOrder FROM TABLE
Order By
CASE SortOrder 
         WHEN 'HC.0' then '01'
         WHEN 'HA.0' then '02'
         WHEN 'AA.0' then '03'
         ELSE '04'
 END

Open in new window

SolarWinds® Network Configuration Manager (NCM)

SolarWinds® Network Configuration Manager brings structure and peace of mind to configuration management. Bulk config deployment, automatic backups, change detection, vulnerability assessments, and config change templates reduce the time needed for repetitive tasks.

Sheldon LivingstonConsultantAuthor Commented:
Sweet!  Thank you.
Sheldon LivingstonConsultantAuthor Commented:
eghtebas, I think I jumped the gun here.  Both solutions error out.
Mike EghtebasDatabase and Application DeveloperCommented:
classnet,

Sorry for the delay, What is the error.

meanwhile try:

SELECT FIELDS1, FIELD2, FIELD3, PHASE ,
CASE LEFT(PHASE,4) 
         WHEN 'HC.0' then '01'
         WHEN 'HA.0' then '02'
         WHEN 'AA.0' then '03'
         ELSE '04'
 END As SortOrder
FROM TABLE
Order By SortOrder

Open in new window


Do you have null PHASE perhaps?

Mike

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.