What should I do if I need to filter the scores in the middle of an SQL string field? The following describes how to filter records of the central score of an SQL string field for your reference.
For example, there is a KKBH (bayonet number) field, which is a dictionary field (corresponding to the number field of another entity table (bayonet table ). The value of this field is saved to the bayonet range {, 02, 03}
Originally, it was implemented through or, which requires dynamic generation of SQL statements.
Then I came up with a method to search for SQL strings using charindex. Make all the ID of the bayonet to be queried into a string similar to '01 @ 02. During SQL query, use charindex to filter the records of KKBH in the SQL string to be queried.
The use of or is similar to that of charindex in MSSQL.
Specific implementation:
User Interface query requirement: You may search for records with N ports (N value range {1, number of all ports }). There are three methods to design this UI:
1. Select one or more listboxes. When the user interface is running, the bayonet dictionary table is loaded into the listbox information.
2. Two listboxes: select on the left, select on the right, and add and delete buttons in the middle. When the user interface is running, the folder dictionary table is loaded into the listbox on the left.
3. Multiple checkboxes. You can directly create an infinite dictionary table during the interface design stage. There are just a few bayonet entries, just a few checkboxes. Or, when the program is running, draw a dynamic checkbox Based on the dictionary table.
The advantages and disadvantages of the UI are not discussed here. I select the third method for dynamic rendering.
In the query phase, the SQL string to be selected is generated based on the selected bayonet: "01 @ 02"
And return this condition to the backend query service program.
In the background query service, as long as the SQL string to be queried is passed into the SQL statement (SQL segment): charindex (bayonet number, @ string to be queried) as the parameter ). Of course, you can also manually generate an SQL statement to pass in "charindex (card port number, '" + query string + "')".