devxlogo

Validating the Data Type in a T-SQL Query

Validating the Data Type in a T-SQL Query

Using the ISNUMERIC() and ISDATE() functions, you can check the required column’s data type validity. If the column passes the data type validity check, it will return a 1. If it fails, it will return a 0.
Example:

 select * from MyTableCompanyID   MyValue----------- -------1           201           101           401           AB(4 row(s) affected)select * from MyTable where ISNUMERIC(MyValue)=1CompanyID   MyValue----------- -------1           201           101           40(3 row(s) affected)select * from MyTable where ISNUMERIC(MyValue)=0CompanyID   MyValue----------- -------1           AB(1 row(s) affected)

devx-admin

Share the Post: