首先在SQL Server(数据库)表中显示选定的字符串 [英] Display selected string first in SQL server (database)table
本文介绍了首先在SQL Server(数据库)表中显示选定的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
如何首先在sql server表中显示所选垃圾
请帮忙!!!!!
预先感谢
振动筛.
我尝试过的事情:
显示从第一个垃圾开始的查询(例如,拼写字母为F)
Hi all
how to display selected litter first in sql server table
Please help!!!!!
Advance thanks
shakeer.
What I have tried:
query to display start with first litter (seleted letter for Example: F)
推荐答案
这很困难-仅显示开始的行很容易与F:
That''s difficult - it''s easy to display just the rows that begin with F:
SELECT * FROM MyTable WHERE MyColumn LIKE 'F%'
但是排序更为复杂,因为SQL没有特别好的字符串处理工具.
您可以做到,但是很麻烦:
But ordering is more complex, because SQL doesn''t have particularly good string handling facilities.
You can do it, but it''s a cludge:
SELECT * From MyTable
ORDER BY CASE WHEN SUBSTRING(MyColumn , 1 , 1) = 'F' THEN 1 ELSE 2 END, MyColumn
它有多种选择,您可以按照OriginalGriff的建议使用LIKE,也可以将LFT函数与CASE运算符一起使用,请参见下面的代码片段
There are multiple option for it, either you can use LIKE as suggested by OriginalGriff or you can use LEFT function with CASE operator, see below snippet
set @checkWord= 'false' when LEFT(@checkWord, 1) = 'F' then 1 else 0 end
或使用CharIndex如下所示
OR use CharIndex as below
set (CharIndex('f', 'false') = 1))
希望对您有帮助
hope it helps
这篇关于首先在SQL Server(数据库)表中显示选定的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文