• Sat. Nov 23rd, 2024

SQL Interview Questions

Byskkumar199650

Aug 17, 2024
sql server

SQL query to find rows that contain only numerical data

Let me explain the scenario mentioned in one of the sql server interview. We have the following table.

 


Write a SQL query to retrieve rows that contain only numerical data. The output of the query should be as shown below.


SQL Script to create the TestTable


Create Table TestTable

(

     ID int identity primary key,

     Value nvarchar(50)

)

Insert into TestTable values (‘123’)

Insert into TestTable values (‘ABC’)

Insert into TestTable values (‘DEF’)

Insert into TestTable values (‘901’)

Insert into TestTable values (‘JKL’)


This is very easy to achieve. If you have used ISNUMERIC() function in SQL Server, then you already know the answer. Here is the query


Select Value from TestTable Where ISNUMERIC(Value) = 1


ISNUMERIC function returns 1 when the input expression evaluates to a valid numeric data type, otherwise it returns 0. For the list of all valid numeric data types in SQL Server please visit the following MSDN link.
http://technet.microsoft.com/en-us/library/ms186272(v=sql.110).aspx

By skkumar199650

Highly skilled and dedicated Software Developer with over 5 years of experience in developing and debugging applications. Proficient in a wide range of technologies, including .NET Technology, Core Java, MS SQL Server, AWS, Liferay, Angular, Ionic, and Azure, Power BI,SSRS,SSIS. I am passionate about delivering robust and scalable software solutions that meet the highest standards. I thrive in collaborative environments, leveraging my strong analytical and problem-solving skills to drive successful outcomes.