| Author |
Topic |
|
leandroengel
Starting Member
3 Posts |
Posted - 2004-12-09 : 15:33:48
|
| Hi everyone,How can I use the LIKE with many options to do a SELECT?For example:SELECT * FROM CLIENT WHERE NAME_CLIENTE LIKE ('joh%', 'carl%', 'j%')I now that I could do as below, but I want use only 1 time the LIKE:SELECT * FROM CLIENT WHERE NAME_CLIENTE LIKE ('joh%') OR NAME_CLIENTE LIKE ('carl%') OR NAME_CLIENTE LIKE ('j%') OR Thanks a lot.Leandro |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-09 : 16:07:44
|
| Why?You have the solution. There is no shorter way.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-12-09 : 16:20:51
|
well its not necessarily shorter, but it may be what he is looking for:Declare @dataTable table (colA varchar(20))Insert Into @dataTableSelect 'Corey Aldebol'Union Select 'Seventhnight'Union Select 'Kaiden Elizabeth'Union Select 'Julie Aldebol'Declare @criteriaTable table (criteria varchar(20))Insert Into @criteriaTableSelect '%Aldebol'Union Select '%Liz%'Select * From @dataTable AInner Join @criteriaTable BOn A.colA like B.criteria Corey |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-12-09 : 16:40:57
|
EDIT: by a good 20 minutes....See...you should have never said never...or no wayUSE NorthwindGOSET NOCOUNT ONCREATE TABLE myTable99(NAME_CLIENTE varchar(20))GOINSERT INTO myTable99(NAME_CLIENTE)SELECT 'AjarnMark' UNION ALL SELECT 'Byrmol' UNION ALL SELECT 'Chadmat' UNION ALL SELECT 'DougG' UNION ALL SELECT 'Ehorn' UNION ALL SELECT 'Frank Kalis' UNION ALL SELECT 'Graz' UNION ALL SELECT 'Harshal_in' UNION ALLSELECT 'izaltsman' UNION ALL SELECT 'jsmith8858' UNION ALL SELECT 'Kristen' UNION ALL SELECT 'Lumbago' UNION ALL SELECT 'Merkin' UNION ALL SELECT 'Nr' UNION ALL SELECT 'Onamuji' UNION ALL SELECT 'Page47' UNION ALL SELECT 'Quazibubble' UNION ALL SELECT 'rrb' UNION ALL SELECT 'SamC' UNION ALL SELECT 'tduggan' UNION ALL SELECT 'Utpal' UNION ALL SELECT 'ValterBorges' UNION ALL SELECT 'Wanderer' UNION ALL SELECT 'x002548' UNION ALL SELECT 'yakoo' UNION ALL SELECT 'zippy'SELECT * FROM myTable99DECLARE @x table(Col1 varchar(20))INSERT INTO @x(Col1) SELECT 'j' UNION ALL SELECT 'c' UNION ALL SELECT 't'SELECT * FROM @xSELECT * FROM myTable99 m INNER JOIN @x x ON m.NAME_CLIENTE LIKE x.Col1 + '%'GO SET NOCOUNT ONDROP TABLE myTable99GO Brett8-) |
 |
|
|
leandroengel
Starting Member
3 Posts |
Posted - 2004-12-09 : 16:54:44
|
| FANTASTIC!!!!!!!Thanks for all!The posts saved my problem!It´s impressing! Just a little time, and you solved my problem!Thanks.Leandro |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-09 : 18:45:25
|
| Maybe we should have asked what the problem was? Seems silly to me to create a table variable/temp table to avoid ORing a few like statements.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-09 : 18:48:09
|
quote: See...you should have never said never...or no way
BTW, I said no shorter way. http://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-12-09 : 20:28:50
|
| well you don't have to create the table - but you probably should for clarity.select tbl.*from tbljoin (select s = 'a%' union all select 'b%' union all select 'c%') aon tbl.fld like a.syou should also use select distinct orselect *from tblwhere exists (select *from (select s = 'a%' union all select 'b%' union all select 'c%') awhere tbl.fld like a.s)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-10 : 11:34:22
|
| I like Nigel's way. While it still uses TempDB, it avoids the temp table.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-12-10 : 12:36:04
|
| Well aren't table variables stored in memory?And why would Nigel's method use tempdb?And wouldn't you have to use dynamic sql if the number of criteria or the criteria itself changes?Brett8-) |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-12-10 : 13:00:32
|
| graz posted something not too long ago (a few months at least) that pointed to a KB article that said table variables will sometimes use tempdb. If the available RAM is not big enough the store the table variable then it would have to go to tempdb. |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-12-10 : 13:14:12
|
Using the splitter you can do:select tbl.*from tbljoin (Select s=data From dbo.Split('a%,%b%,%c',',')) aon tbl.fld like a.sNo table variable, to temp table... only the udf.Corey |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-10 : 16:14:53
|
quote: Originally posted by X002548 Well aren't table variables stored in memory?And why would Nigel's method use tempdb?And wouldn't you have to use dynamic sql if the number of criteria or the criteria itself changes?Brett8-)
1. No, Table Variables always use TempDB, they really are no different that temp table except that they go away automaically when they go out of scope, and you can't put indexes on them.2. Unions use TempDB-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-10 : 16:29:40
|
| Let me clarify, in the same way a temp table works, if the table will fit in memory, it won't necissarily use TempDB, but it is no different than a Temp Table in it's memory/tempdb behavior.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-12-10 : 16:30:13
|
quote: Originally posted by chadmat No, Table Variables always use TempDB, they really are no different that temp table
Huh?Not that it references it in BOL, but Brian Knight doesquote: One reason the table data type is so much faster is that it doesn't occupy space in the tempdb database as it's temporary table counterpart. Instead, the table data type uses the SQL Server's memory to store the data
Brett8-) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-12-10 : 16:32:12
|
quote: Originally posted by chadmat Let me clarify, in the same way a temp table works, if the table will fit in memory, it won't necissarily use TempDB, but it is no different than a Temp Table in it's memory/tempdb behavior.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime.
OK, but doesn't a temp table always go to te,pdb?Brett8-) |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-12-10 : 16:34:18
|
| Yes. And like all tables, it can also gets cached in the data buffer. A cached temp table performs no worse than a table variable, and if it's indexed and stat'ed, it can perform even better. |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-10 : 16:37:21
|
quote: Originally posted by X002548
quote: Originally posted by chadmat No, Table Variables always use TempDB, they really are no different that temp table
Huh?Not that it references it in BOL, but Brian Knight doesquote: One reason the table data type is so much faster is that it doesn't occupy space in the tempdb database as it's temporary table counterpart. Instead, the table data type uses the SQL Server's memory to store the data
Brett8-)
quote: Q4: Are table variables memory-only structures that are assured better performance as compared to temporary or permanent tables, because they are maintained in a database that resides on the physical disk?A4: A table variable is not a memory-only structure. Because a table variable might hold more data than can fit in memory, it has to have a place on disk to store data. Table variables are created in the tempdb database similar to temporary tables. If memory is available, both table variables and temporary tables are created and processed while in memory (data cache).
http://support.microsoft.com/default.aspx?scid=kb;en-us;305977http://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-12-10 : 16:43:47
|
quote: OK, but doesn't a temp table always go to te,pdb?
Yes, as does a table variable.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-12-10 : 17:06:04
|
Now now gentlemen... you don't really even need either in this case pthbbbbt!Corey |
 |
|
|
Next Page
|