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
 General SQL Server Forums
 New to SQL Server Programming
 how to get all the frields that start with Numbers

Author  Topic 

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-04-26 : 18:25:42
I am trying to get all the fields that start with number(s)

is there a better way to acomplish this than the way I am doing it now ?


select * from mytable
where word like '1%' and
word like '2%' and
word like '3%' and
word like '4%' and
word like '5%' and
word like '6%' and
word like '7%' and
word like '8%' and
word like '9%' and
word like '0%'

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-04-26 : 18:30:38
This should do the same thing and be a little more compact:
select * from mytable 
where word LIKE '[0-9]%'
-Ryan
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-26 : 18:30:50
like '[0-9]%'


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-26 : 18:32:37


"This should do the same thing"
Actually it does not. The "like '1%' and word like '2%' and . . ." would return no result


KH

Go to Top of Page

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-04-26 : 18:32:46
thank you, very much, first time I use this forum and my two questions got answered within minute. I appreciate it
Go to Top of Page

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-04-26 : 18:34:15
quote:
Originally posted by khtan



"This should do the same thing"
Actually it does not. The "like '1%' and word like '2%' and . . ." would return no result


KH





ok, now I am comfused ... sorry
Go to Top of Page

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-04-26 : 18:35:35
ok my bad ya in my original sample I should have say OR not and
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-26 : 18:39:10
Any single can't both start with 1 AND 2...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-04-26 : 19:01:54
quote:
Originally posted by khtan



"This should do the same thing"
Actually it does not. The "like '1%' and word like '2%' and . . ." would return no result


KH





Hehe, I went with the requirement: "I am trying to get all the fields that start with number(s)." Not the actual code. :)
Go to Top of Page
   

- Advertisement -