In this example, we use the sqlleft function to retrieve characters and then perform like or fuzzy query of data in our own range based on the user input. For more information, see.
In this example, we use the SQL left function to retrieve characters and then perform like or fuzzy query of data in our own range based on the user input. if you need it, let's take a simple reference.
Problem
The data is
ID string
1 A0000000001
2 A0000000002
3 A0000000003
4 A0000000004
5 A0000000005
6 A0000000006
7 A0000000007
Requirements:
A query range is provided, for example
A0000000003, A0000000006
SQL execution statement
| The code is as follows: |
|
|
Create table t10 (ID int, string code varchar (20 ))
Insert into t10
1, 'a0000000001 'union all
Select 2, 'a0000000002' union all
Select 3, 'a0000000003' union all
Select 4, 'a0000000004' union all
Select 5, 'a0000000005 'union all
Select 6, 'a0000000006 'union all
Select 7, 'a0000000007'
-- String input in the program @ x
Declare @ x varchar (50)
Select @ x = 'a0000000003, A0000000006'
Select * from t10
Where string code between left (@ x, charindex (',', @ x)-1)
And substring (@ x, charindex (',', @ x) + 1, 20)
ID string
-------------------------------
3 A0000000003
4 A0000000004
5 A0000000005
6 A0000000006 |