| |

VerySource

 Forgot password?
 Register
Search
Author: aquacn

How do you handle wildcards when querying?

[Copy link]

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-1-28 12:27:01
| Show all posts
Example: select * from tablename where column like '% [%]%'-this way you can find the rows that contain '%' in a column

Enlarging the "%" with brackets "[]" is considered a normal character
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-28 12:54:01
| Show all posts
Why not use the charindex () function?

select * from # where charindex ('15% ', a)> 0
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-1-28 13:27:01
| Show all posts
select * from
(
select col = '15 '
union all select '% 15%'
union all select '% 15'
union all select '15% '
) a
where a.col like '% [%]%'
Reply

Use magic Report

0

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-29 17:54:02
| Show all posts
select * from a where [name] like '% 15 [%]%'
select * from A where charindex ('15% ', [name])> 0 pairs
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-7 17:15:01
| Show all posts
Use the ESCAPE keyword to define escape characters. In the pattern, when the escape character is placed before the wildcard, the wildcard is interpreted as a normal character. For example, to search for a string containing 5% of the string anywhere, use:
WHERE ColumnA LIKE '15/%%' ESCAPE'/'
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-7 17:30:01
| Show all posts
Use the ESCAPE keyword to define escape characters. In the pattern, when the escape character is placed before the wildcard, the wildcard is interpreted as a normal character. For example, to search for strings that contain 15% of the string anywhere, use:
WHERE ColumnA LIKE'%15/%%' ESCAPE'/'
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-8-7 19:30:02
| Show all posts
Learned learned
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list