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 |
|
raghulvarma
Starting Member
21 Posts |
Posted - 2010-04-01 : 06:21:41
|
| using OracleA table has 3 rows and 3 cols, Here col1,col2,col3 are all varcharCol1 Col2 Col3A AA AAAB BB BBBC CC CCCNow I write a select QuerySelect * from table where col1 like '%'it returns all the rowsNow i put another query Select * from table where '%' like col1it does not return any valuesbut when I change the query asSelect * from table where col1 like 'A'it returns the first rowNow i put another query Select * from table where 'A' like col1it returns the first rowNow the question is if I give the record value ("A") it returns correct values but if i give a wild card character it does not return the value WHY? |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-04-01 : 06:28:17
|
"Select * from table where '%' like col1it does not return any values"I think you meant to typeSelect * from table where col1 like '%' In your version SQL is correcting saying that "%" is not like "A", nor like "B" nor like "C" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-04-01 : 06:30:33
|
The wild card character should be on the right hand side on the left side of the "LIKE".Putting it on the left side does not perform any LIKE matching at all and hence yield no result.Not sure how does this behave in Oracle but at least it is in SQL Server.Incase you didn't notice, you have posted in New to SQL Server programming KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2010-04-01 : 06:38:29
|
| Because as per LIKE syntax pattern is specified on the right hand side of the operator. 'A' like Col1 works because it is not pattern matching, but string matching.Harsh Athalyehttp://www.letsgeek.net/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-01 : 06:40:08
|
| <<Not sure how does this behave in Oracle but at least it is in SQL Server.>>It works same way as how it works in SQL ServerMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|