How to compare the decimal?

• Question

```declare @t table(id int,value decimal(18,2))
insert into @t
select 1,10.22 union
select 2,200.00

select * from @t where value<7.5
```

return null, if i run:

```select * from @t where value<'7.5'
```

also return null, how to compare the decimal column?Thanks.

Regards

Garey

Wednesday, June 29, 2011 11:01 AM

• I got both NULLs,looks like 10.22 and 200  is greater than 7.5 :-) No?

declare @t table(id int,[value] decimal(18,2))

insert into @t

select 1,10.22 union

select 2,200.00

select * from @t where [value]<7.5

--return null, if i run:

select * from @t where [value]<'7.5'

Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
• Proposed as answer by Wednesday, June 29, 2011 2:45 PM
• Marked as answer by Thursday, June 30, 2011 1:28 AM
Wednesday, June 29, 2011 11:04 AM
• Your query is right, try to reverse >

```declare @t table(id int,value decimal(18,2))
insert into @t
select 1,10.22 union
select 2,200.00
select * from @t where value>7.5
--1 10.22
--2 200.00
```

Best regards
• Proposed as answer by Wednesday, June 29, 2011 2:20 PM
• Marked as answer by Thursday, June 30, 2011 1:28 AM
Wednesday, June 29, 2011 11:04 AM
• I add other value to the table and it works :

```declare @t table(id int,value decimal(18,2))
insert into @t
select 1,10.22 union
select 2,200.00 union
select 3,6.5
select * from @t where value<7.5
--1 6.50
```

Best regards
• Marked as answer by Thursday, June 30, 2011 1:28 AM
Wednesday, June 29, 2011 11:07 AM

```declare @t table(id int,value decimal(18,2))
insert into @t
select 1,10.22 union
select 2,200.00

select * from @t where value<7.5
```

return null, if i run:

```select * from @t where value<'7.5'
```

also return null, how to compare the decimal column?Thanks.

Regards

Garey

110.22 and 2200.00 values are not less then "<" of value 7.5

thanks,

• Proposed as answer by Wednesday, June 29, 2011 2:20 PM
• Marked as answer by Thursday, June 30, 2011 1:28 AM
Wednesday, June 29, 2011 11:12 AM

All replies

• I got both NULLs,looks like 10.22 and 200  is greater than 7.5 :-) No?

declare @t table(id int,[value] decimal(18,2))

insert into @t

select 1,10.22 union

select 2,200.00

select * from @t where [value]<7.5

--return null, if i run:

select * from @t where [value]<'7.5'

Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
• Proposed as answer by Wednesday, June 29, 2011 2:45 PM
• Marked as answer by Thursday, June 30, 2011 1:28 AM
Wednesday, June 29, 2011 11:04 AM
• Your query is right, try to reverse >

```declare @t table(id int,value decimal(18,2))
insert into @t
select 1,10.22 union
select 2,200.00
select * from @t where value>7.5
--1 10.22
--2 200.00
```

Best regards
• Proposed as answer by Wednesday, June 29, 2011 2:20 PM
• Marked as answer by Thursday, June 30, 2011 1:28 AM
Wednesday, June 29, 2011 11:04 AM
• I add other value to the table and it works :

```declare @t table(id int,value decimal(18,2))
insert into @t
select 1,10.22 union
select 2,200.00 union
select 3,6.5
select * from @t where value<7.5
--1 6.50
```

Best regards
• Marked as answer by Thursday, June 30, 2011 1:28 AM
Wednesday, June 29, 2011 11:07 AM

```declare @t table(id int,value decimal(18,2))
insert into @t
select 1,10.22 union
select 2,200.00

select * from @t where value<7.5
```

return null, if i run:

```select * from @t where value<'7.5'
```

also return null, how to compare the decimal column?Thanks.

Regards

Garey

110.22 and 2200.00 values are not less then "<" of value 7.5

thanks,