“组合”上的 T-SQL 搜索列名
我想知道是否可以在两个组合列上进行搜索。例如,在我的应用程序中,我有一个“全名”输入字段,但在 SQL 数据库中,我有“姓名”列。
是否可以构造一个查询来执行类似 Name + Surname = %Full Name% 的搜索?
I would like to know if its possible to search on two combined columns. For instance in my application I have an input field for 'Full Name', but in the SQL Database I have columns Name, Surname.
Is it possible to construct a query to do a search like Name + Surname = %Full Name% ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以这样做:
但是,如果您想利用索引,最好先拆分输入参数,然后使用直接字段比较。
You can do this:
However, if you want to take advantage of indexing, you better split you your input parameter first and then use direct field comparison.
是的,你可以这样做,但速度会很慢。由于姓名和姓氏可以被索引。
Yes you can do this, but it will be quite slow. Since Name and Surname can be indexed.
扩展之前答案的建议,试试这个。
希望这有帮助。
Expanding on the suggestions from previous answers, try this.
Hope this helps.
如果磁盘空间不是问题,您可以添加一个带有全名的“持久”计算列,这样您就可以维护两个特定列的细节,同时实现对全名列进行索引的可能性,该全名列在名字或姓氏时自动更新变化。
需要注意的是需要额外的空间以及插入速度稍慢。如果这两种情况是一个问题,您可以使用不具有持久性的计算列来获得透明的全名列和更清晰的查询。
http://msdn.microsoft.com/en-us/library/ms189292.aspx
If disk space is not a concern you can add a 'persistent' calculated column with the fullname this way you can maintain the specifics of two specific columns while achieving the possibility of indexing the full name column that is auto updated when either first or last name changes.
The caveats are the extra space needed as well as the somewhat slower inserts. If these two situations are a concern you can use the calculated columns without persistence to get a transparent fullname column and cleaner queries.
http://msdn.microsoft.com/en-us/library/ms189292.aspx