sQL query valid value and only 2 decimal places

I want to return all the records where there are more then 2 numbers after the decimal place OR the number is not numer.

For example 122.332
.342

etc
vbnetcoderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vikas GargAssociate Principal EngineerCommented:
Hi,

You can use this

SELECT *  FROM Table
WHERE SQL_VARIANT_PROPERTY(DecimalColumn, 'Scale') >= 3

Open in new window

vbnetcoderAuthor Commented:
I need something that will also work in access.  Would that?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you can try customize:
create table yourtable
(
  yourfield varchar(20)
);
insert into yourtable(yourfield) values ('234.22');
insert into yourtable(yourfield) values ('bla');
insert into yourtable(yourfield) values ('122.332');
insert into yourtable(yourfield) values ('.342');

select a.*, charindex('.',a.yourfield) idx 
from yourtable a
where (charindex('.',yourfield) >0
and len(a.yourfield)- charindex('.',yourfield)>=3)
or isnumeric(a.yourfield)=0

Open in new window

Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

vbnetcoderAuthor Commented:
Isn't there something simpler? the field in the database is text not numeric so perhaps i could use string functions of some sort

1) i check if the value is a number (i know how to do that)
2) if it is a valid number insure that there are only two  values after the decimal place
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>1) i check if the value is a number (i know how to do that)
>>2) if it is a valid number insure that there are only two  values after the decimal place
since there are 2 different scenarios to handle, I think it cannot be simplified to the way you wish it to be.

The example I provided in comment: ID: 41021493 could be a "simple" solution which cannot be further simplified.
vbnetcoderAuthor Commented:
Yes sorry i misread to solution,  sorry!

Could you add one more piece in for me?  There can only be only 9 digits to the right of the left of the decimal place
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>There can only be only 9 digits to the right of the left of the decimal place
can you provide me some examples?
vbnetcoderAuthor Commented:
these would be valid
999999999.99
999999999

these would not be valid

9999999999.99
9999999999
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ok, you probably can try this:

create table yourtable
(
  yourfield varchar(20)
);
insert into yourtable(yourfield) values ('234.22');
insert into yourtable(yourfield) values ('bla');
insert into yourtable(yourfield) values ('122.332');
insert into yourtable(yourfield) values ('.342');
insert into yourtable(yourfield) values ('999999999.99');
insert into yourtable(yourfield) values ('999999999');
insert into yourtable(yourfield) values ('9999999999.99');
insert into yourtable(yourfield) values ('9999999999');
insert into yourtable(yourfield) values ('123456789.123');
insert into yourtable(yourfield) values ('1000000000');

select a.*, charindex('.',a.yourfield) idx 
from yourtable a
where 
(charindex('.',yourfield) >0 and len(a.yourfield)- charindex('.',yourfield)>=3) or
(charindex('.',yourfield) >0 and charindex('.',yourfield)>=11) or
isnumeric(a.yourfield)=0 or
(isnumeric(a.yourfield)=1 and convert(money, a.yourfield) >= 1000000000)

Open in new window

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
this could be simplified to:

select a.*, charindex('.',a.yourfield) idx 
from yourtable a
where 
(charindex('.',yourfield) >0 and len(a.yourfield)- charindex('.',yourfield)>=3) or
isnumeric(a.yourfield)=0 or
(isnumeric(a.yourfield)=1 and convert(money, a.yourfield) >= 1000000000)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
Take the substring of your field from the decimal point and if the length is greater than 3 it would mean there are more than 2 decimal places.
vbnetcoderAuthor Commented:
i will get back to this
vbnetcoderAuthor Commented:
ty
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.