Brian's Blog

items I see across my tribes

Convert Text String to Numbers (Int)

July 22
by briancarter 22. July 2010 06:38

Here is a simple method to convert a text string to numbers (or an integer). This method evaluates each value in a column to determine if the datatype is numeric. If it is, then it converts it to an integer.

SELECT
    CASE WHEN
        ISNUMERIC(PostalCode) > 0
    THEN CAST(PostalCode AS INT)
    ELSE 0 END
FROM Sales.Address

Categories: Development

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading




 Questions or Feedback, my contact information is located on my About page.


The opinions, thoughts, and comments made in these blog posts are solely my own (unless otherwise stated). They do not reflect the opinions, thoughts or practices of my employer, my universities, my family, or anyone else. Also, I retain the right to change my mind about anything I publish here without having to go back and edit posts that occurred in the past. 

These are my opinions, or just as likely, someone else's opinions that I leveraged for my own.