mercredi 31 août 2016

sql server - check to see if cast is possible then use in order clauses

I have a varchar(20) column, need to convert to int and use in order clauses. But things is okay when it is possible to convert. My code:

            SELECT    DISTINCT people.ParYear,CAST(people.ParID As int), people.Pfamily, people.Pname
            FROM               people 
                WHERE                        people.osID    = @osID 
                         AND people.shID    = @shID
                         AND people.ParYear = @ParYear
               ORDER BY        people.ParYear, CAST(people.ParID As int)

So how can I avoid error Message like Conversion failed!

Aucun commentaire:

Enregistrer un commentaire