Cog

Using The CAST Function In SQL To String Search Number Columns

Posted by Weston Ganger on June 29, 2015

I was working on an application and part of one of the searches needed to search numbers like a string. Normally in SQL if you search a number it will look for an exact match or less than or greater than kind of thing.


# replace 14 with your search value
... WHERE CAST(ProductID as CHAR) LIKE '%14%'

Now if you search 14, it will return entries with 14, 2014, 7814, 8881488.


Related External Links:


Posted in Web Development and Tagged with sql search 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts