Home All Groups Group Topic Archive Search About

Select whole numbers in decimal field

Author
5 Jan 2006 4:54 PM
Terri
I have a decimal field. Decimal (18,4)

How can I only select whole numbers from this field or vice versa?

Thanks

Author
5 Jan 2006 5:06 PM
Payson
Not sure I understand the question fully, but here is a guess.

CREATE TABLE #Trash (t1 DECIMAL(18,4))
INSERT INTO #Trash (t1) values(1)
INSERT INTO #Trash (t1) values(1.1)
INSERT INTO #Trash (t1) values(2)
INSERT INTO #Trash (t1) values(1.9999)
INSERT INTO #Trash (t1) values(2.0001)

SELECT t1
FROM #Trash
WHERE CAST(t1 AS INTEGER) = t1

SELECT t1
FROM #Trash
WHERE CAST(t1 AS INTEGER) <> t1

DROP TABLE #Trash

Payson

Terri wrote:
Show quote
> I have a decimal field. Decimal (18,4)
>
> How can I only select whole numbers from this field or vice versa?
>
> Thanks
Author
5 Jan 2006 5:10 PM
Mark Williams
SELECT [number] FROM [Numbers]
WHERE FLOOR([number]) = [number]

Should get you the whole numbers.

--



Show quote
"Terri" wrote:

> I have a decimal field. Decimal (18,4)
>
> How can I only select whole numbers from this field or vice versa?
>
> Thanks
>
>
>
Author
5 Jan 2006 6:28 PM
Terri
Thanks the FLOOR function is wahat I needed.

"Mark Williams" wrote
Show quote
> SELECT [number] FROM [Numbers]
> WHERE FLOOR([number]) = [number]
>
> Should get you the whole numbers.
>
> --
>
>
>
> "Terri" wrote:
>
> > I have a decimal field. Decimal (18,4)
> >
> > How can I only select whole numbers from this field or vice versa?
> >
> > Thanks
> >
> >
> >
Author
9 Jan 2006 7:05 PM
Payson
Sorry to be so late with this.  Does floor give you what you need with
negative numbers?

Payson

Terri wrote:
Show quote
> Thanks the FLOOR function is wahat I needed.
>
> "Mark Williams" wrote
> > SELECT [number] FROM [Numbers]
> > WHERE FLOOR([number]) = [number]
> >
> > Should get you the whole numbers.
> >
> > --
> >
> >
> >
> > "Terri" wrote:
> >
> > > I have a decimal field. Decimal (18,4)
> > >
> > > How can I only select whole numbers from this field or vice versa?
> > >
> > > Thanks
> > >
> > >
> > >

AddThis Social Bookmark Button