如何搜索列值
表 1
Values
9A 200x400x600
10B 400x200x500
....
值列数据类型为 nvarchar
查询
Select * from table1 where values like '" & textbox1.text & "%'
上述查询有效,但我想以 4 种方式进行搜索
我想用每 3 位数字搜索一列
查询不应检查 space
和 x< /code> 列中的值。
预期输出
- 如果我输入 textbox1 9A 或 10A,查询应返回前 2 或 3 个值
- 如果我输入 textbox2 200 或 400,查询应从第一行返回 200 或从第二行返回 400
- 如果我输入 textbox3 400 或 200 查询应该从第一行返回 400 或从第二行返回 200
- 如果我在 textbox4 中输入 600 或 500 查询应从第一行返回 600,从第二行返回 500
如何拆分搜索的列值
需要查询帮助
Table1
Values
9A 200x400x600
10B 400x200x500
....
Values Column datatype is nvarchar
Query
Select * from table1 where values like '" & textbox1.text & "%'
The above query is working, but I want to search in 4 ways
I want to search a column with every 3 digit
The query should not check space
and x
values from the column.
Expected Output
- if I type in textbox1 9A or 10A the query should return first 2 or 3 values
- If I type in textbox2 200 or 400 the query should return 200 from first row or 400 from second row
- If I type in textbox3 400 or 200 the query should return 400 from first row or 200 from second row
- If I type in textbox4 600 or 500 the query should return 600 from first row and 500 from second row
How to split the column value for search
Need query help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如您所知,该查询是一个有点混乱的问题。我会尝试,让我知道这是否接近您正在寻找的。
我假设:
那么,查询是:
已编辑:
As you know the query is a the question is a bit confused. I will try, let me know if this is close that you are looking for.
I assume that:
Then, the query is:
edited:
请研究数据库规范化,特别是第一范式。
目前,您的数据字段
values
用于在一行中保存多个不同的值 - 例如。9A 200x400x600
。 (不仅如此,您还在同一字段中使用不同的值分隔符,因为和
x
都用于分隔字段。)SQL 不是为此设计的某种操纵。
虽然可以生成返回相关值的查询,但这样的查询会很笨重且不灵活。因此我建议规范化数据结构,以更适合查询。
Please look into database normalisation, particularly first normal form.
At present, your data field
values
is being used to hold multiple different values in a single row - eg.9A 200x400x600
. (Not only that, but you are also using different value delimiters in the same field, as bothand
x
are being used to delimit fields.)SQL is not designed for this sort of manipulation.
While it would be possible to produce a query that would return the relevant values, such a query would be unwieldy and inflexible. I therefore suggest normalising the data structure, to be more suitable for querying.