Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select number like

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-11-12 : 06:00:52
There is a field in a table as decimal(15, 2)
I would like to return all the numbers beginning with 9
Is this the best way to do this?
i.e.
select field1 from table1 where field1 like '9%'

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-12 : 06:03:38
Try this:
select field1 from table1 where convert(varchar(50),field1) like '9%'



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-12 : 07:18:00
quote:
Originally posted by arkiboys

There is a field in a table as decimal(15, 2)
I would like to return all the numbers beginning with 9
Is this the best way to do this?
i.e.
select field1 from table1 where field1 like '9%'

Thanks


Yes. That is the best way if the column in indexed

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-12 : 07:34:28
Oops!
I was sure that this operation "like '9%'" isn't possible on non-character-columns, hence I never had the idea to try it.

I've learned something new - like every other day before.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-12 : 07:38:37
quote:
Originally posted by webfred

Oops!
I was sure that this operation "like '9%'" isn't possible on non-character-columns, hence I never had the idea to try it.

I've learned something new - like every other day before.


No, you're never too old to Yak'n'Roll if you're too young to die.


It is because you are matching the numbers only using LIKE

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-11-12 : 09:44:23
Thanks
Go to Top of Page
   

- Advertisement -