Sfwd favicon 152

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 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts