SQL Server中的like语句 [英] like statement in sql server

查看:129
本文介绍了SQL Server中的like语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想显示以
开头的员工姓名 "San".但是当我在sql中使用"Like"语句时,我显示的是所有连续带有字母"San"的名称.



我的代码如下...


从tabName中选择*,其中empName如"San%"


请帮助我获取仅以"San"开头的名称



例如.输出是
该表包含以下EmpName

1.santhanam
2.桑瑟斯
3.玛格桑

如果我使用上述查询,它将显示所有名称.但是我只想获取以"San"开头的名称.我需要以下名称,

1.santhanam
2.桑瑟斯



在此先感谢朋友.........

I want to display only the name of employees that starts only with
"San".But when i am using the "Like" statement in sql i shows ,all the names that is having the letters "San" continuously.



My code is as follows...


select * from tabName where empName like "San%"


please help Me to get the names that only starts with "San"



Eg. Output is
the table contains the following EmpName

1.santhanam
2.Santhose
3.Magesan

If i use the above query,It will display all the names.But I want to get only the names That are starts with "San".I need the following names,

1.santhanam
2.Santhose



Thanks in advance friends.........

推荐答案

如果起始字符数固定,则可以使用以下查询:

you can use your query something like below if number of starting characters are fix :

select * from tabName where left(EmpName,3) = 'San'


select * from tablename where empName like 'san_%'


这篇关于SQL Server中的like语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆