| |

VerySource

 Forgot password?
 Register
Search
View: 1413|Reply: 11

How to write a Select sentence.

[Copy link]

2

Threads

12

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-13 23:30:02
| Show all posts |Read mode
How to retrieve such records from the database
Book title, the topic to which the book belongs book_ztid:
Title A 4
Title B 2,4,5
Title C 3,5,14,24,25,34
Title D 4, 24

Search for records with topic book_ztid 4 now
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-10 14:45:01
| Show all posts
select * from table where charindex(',4,',book_ztid)>0
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-6-10 15:30:01
| Show all posts
select * from tablename where charindex('4',book_ztid)>0
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-10 17:30:01
| Show all posts
select * from table where charindex(',4,',','+book_ztid+',')>0
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-6-10 18:00:02
| Show all posts
select * from tablename where charindex(',4,',','+book_ztid+',')>0
Reply

Use magic Report

2

Threads

12

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-6-10 21:15:01
| Show all posts
Let me try it.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-6-11 23:30:01
| Show all posts
create table T(book_name nvarchar(10), book_ztid varchar(20))
insert T select'Book Title A', '4'
union all select'Book Title B', '2,4,5'
union all select'Book Title C', '3,5,14,24,25,34'
union all select'Book Title D', '4,24'

select * from T
where charindex(',4,',','+book_ztid+',')>0

--result
book_name book_ztid
---------- --------------------
Title A 4
Title B 2,4,5
Title D 4,24

(3 row(s) affected)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-12 17:30:01
| Show all posts
select * from tablename where tablename where book_ztid like '4' or book_ztid like'%,4,%' or book_ztid like '4,%' or book_ztid like'%,4'
Reply

Use magic Report

2

Threads

12

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-22 20:00:02
| Show all posts
If it is the ACESS database.
Reply

Use magic Report

2

Threads

12

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-22 20:45:01
| Show all posts
Thewzx198846method can be used in ACESS. .

Are there any shorter sentences.
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