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.
| Author |
Topic |
|
hmusa
Starting Member
36 Posts |
Posted - 2002-04-02 : 02:39:20
|
| I'm sure this is very easy but cannot find it anywhere on the site.I want to select all records that begin with a number to f , I can construct the "A" to "F" part but how do I include in my select statement the numeric records.thanxs in advance |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-04-02 : 03:02:13
|
| Am not sure what you are asking for. if you meant searching records starting with a specific number in a column.here it isselect * from tablename where columnname like '4%'It will work for both numeric and character datatype.HTH-------------------------------------------------------------- |
 |
|
|
hmusa
Starting Member
36 Posts |
Posted - 2002-04-02 : 03:07:47
|
| This is what I am looking for but I thought there might be an easy way to select all records that start with a number instead of writing a select statement with a like clause for every number I am searching for. |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-04-02 : 03:28:15
|
| you can create a sp and do it easilycreate procedure (@startnotosearch int)asset nocount ondeclare @strSql as varchar(500)select @strSql='select * from tablename like '''+ltrim(str(@a))+'%'''exec (@strSql)GoRemember this will be slower comparatively coz it is using Dynamic Sql and Dynamic Sql doesnt uses Chache plan.-------------------------------------------------------------- |
 |
|
|
Teroman
Posting Yak Master
115 Posts |
Posted - 2002-04-02 : 04:36:25
|
| --avoid dynamic SQL, just do thiscreate procedure myProc @n intas set nocount on select * from myTablewhere myColumn like rtrim(str(@n))+ '%'Go also avoids a couple of typos ;)col |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-04-02 : 07:37:57
|
Hmusa, Teremon stored procedure does the trick , replace rtrim with ltrim .they inadverently creep up, cant help  quote: also avoids a couple of typos ;)
--------------------------------------------------------------Edited by - Nazim on 04/02/2002 07:40:33 |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2002-04-02 : 07:48:26
|
| Uh, isn't hmusa (gesundheit!) just asking forSELECT * FROM tablename WHERE columnname LIKE '[0-9A-F]%'? |
 |
|
|
dsdeming
479 Posts |
Posted - 2002-04-02 : 07:51:06
|
| You could also use the ISNUMERIC function:WHERE SELECT ISNUMERIC( LEFT( columnname, 1 )) = 1Edited by - dsdeming on 04/02/2002 07:51:41 |
 |
|
|
hmusa
Starting Member
36 Posts |
Posted - 2002-04-02 : 08:35:52
|
Arnold you hit the nail on the head. Thank You |
 |
|
|
|
|
|