如何从sql中的列中搜索名字? [英] how to search First name from a column in sql ?
问题描述
嗨....
i有一张桌子,我在一栏中输入员工全名......就像这样 -
id Empname LoanSubscriptionDate IsActive
1 Rohit Kumar 30/12/2013 1
2 BabuLal Tiwari 4/08/2012 0
3 Ramcharan Kumar Garg 9/11/2013 1
我想要一份清单名称只包含名字,即(如上表所示结果集)---
Emp
Rohit
BabuLal
Ramcharan
请给出任何想法...
hi ....
i have a table in which i am entering employee full name in one column ... like this -
id Empname LoanSubscriptionDate IsActive
1 Rohit Kumar 30/12/2013 1
2 BabuLal Tiwari 4/08/2012 0
3 Ramcharan Kumar Garg 9/11/2013 1
And i want a list of name which only contain first name , i.e. (as given result set of above table ) ---
Emp
Rohit
BabuLal
Ramcharan
Pls give any idea ...
推荐答案
T-SQL:最实用的分割功能 [ ^ ]
假设在第一个名字之后你有空格你可以试试这个:
SELECT LEFT(Empname,CHARINDEX('',Empname) - 1)AS FistName FROM YourTable
Hi, assuming that after the first name you have a space you can try this:
SELECT LEFT(Empname, CHARINDEX(' ', Empname) - 1) AS FistName FROM YourTable
这篇关于如何从sql中的列中搜索名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!