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?
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 GargBusiness Intelligence DeveloperCommented:
Hi,

You can use this

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

Open in new window

0
vbnetcoderAuthor Commented:
I need something that will also work in access.  Would that?
0
Ryan ChongCommented:
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

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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
0
Ryan ChongCommented:
>>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.
0
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
0
Ryan ChongCommented:
>>There can only be only 9 digits to the right of the left of the decimal place
can you provide me some examples?
0
vbnetcoderAuthor Commented:
these would be valid
999999999.99
999999999

these would not be valid

9999999999.99
9999999999
0
Ryan ChongCommented:
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

0
Ryan ChongCommented:
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

0

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
awking00Commented:
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.
0
vbnetcoderAuthor Commented:
i will get back to this
0
vbnetcoderAuthor Commented:
ty
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.