SQL - seraching for a real number in SQL database

Posted on 2012-03-14
Medium Priority
Last Modified: 2012-08-13
I am looking for a store procedure that will help to search a real number for example 91.91

Any one know how to do it or any exisiting store procedure?

Question by:tommym121
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37720126
It's a select statement.

create procedure searchNum
@input  Real

select * from <table> where <col> = @input
LVL 32

Expert Comment

ID: 37720471
Search in what? A column in a table, all columns in a table, all tables in a schema, all tables in a database?

Author Comment

ID: 37721176
I am try to search in the database for such a number (real and money)
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37721216
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37724930
Shows the framework of how to loop through the entire database.  

Just change the last exec statement to not bring back the Left part of the column.

and change the where to @ColumnName = @SearchStr2

Author Comment

ID: 37742225

Real number is approximate not precise,  I need to set a tolerance like  abs(@ColumnName - @SearchStr2)/@SearchStr2 < Tolerance to see if @ColumnName = @SearchStr2.  Tolerance can be 10E-6

Author Comment

ID: 37742231
How do I put such a formula in SQL where statement?
LVL 40

Accepted Solution

Kyle Abrahams earned 2000 total points
ID: 37743215
In that case do a between:

declare @min
declare @max

set @min = subtract tolerance from value

set @max = add tolerance to value

where @columnName between @min and @max

Author Closing Comment

ID: 37745731

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question