| |

VerySource

 Forgot password?
 Register
Search
View: 2348|Reply: 16

How do you handle wildcards when querying?

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-20 00:00:01
| Show all posts |Read mode
Now in my query I want to query 15% of the data, but SQL will consider this percent sign as a wildcard, but I just want to query 15% of the data, what should I do?
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-28 07:00:01
| Show all posts
Only the like operator will treat% as a wildcard, right? = No, right?
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-28 08:45:01
| Show all posts
Oh yes, it's a string match which contains 15%
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-28 08:54:01
| Show all posts
create table # (a varchar (20))
insert into # select '15% '

select * from # where a = '15% '

sure. . .
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-1-28 09:09:01
| Show all posts
select * from tablename where column like '% 15 [%]%'
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-28 09:27:01
| Show all posts
A post previously discussed how to escape% into ordinary characters, the landlord may wish to search.
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-28 09:45:01
| Show all posts
Then add another one?
select * from # where a like '15 %% '
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-28 10:36:01
| Show all posts
Nope. . Ignore it. .
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-28 11:45:02
| Show all posts
TO:prajna
This will also query the data containing 15.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-28 12:09:02
| Show all posts
select * from
(
select col = '15 '
union all select '% 15%'
union all select '% 15'
union all select '15% '
) a
where a.col = '15% '

--result
col
----
15%

(1 row (s) affected)
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