Sql 选择应按提供的字母查找单词的程序

Sql 选择应按提供的字母查找单词的程序,sql,sql-server-2008,tsql,select,stored-procedures,Sql,Sql Server 2008,Tsql,Select,Stored Procedures,我有一个程序,它正在工作,但我想改善它,通过给予能力,搜索的夫妇字母在word中。程序: alter PROCEDURE SearchByIncIDroNameOfClientoStreetorEmpID @IncID int, @NameOfClient nvarchar (60), @StrID int, @EmpID int, @date date as select IncID,NameOfClient,EnterDate,StrName ,AppartmentNumber as 'ap

我有一个程序,它正在工作,但我想改善它,通过给予能力,搜索的夫妇字母在word中。程序:

alter PROCEDURE SearchByIncIDroNameOfClientoStreetorEmpID
@IncID int,
@NameOfClient nvarchar (60),
@StrID int,
@EmpID int,
@date date
as
select IncID,NameOfClient,EnterDate,StrName ,AppartmentNumber as 'appartment',Summary,IncStatus,e.LastName,EndDate 
from Incident i 
JOIN Streets s on i.StrID=s.StrID 
join Employee e on i.EmpID=e.EmpID
where  IncID =@IncID or NameOfClient = @NameOfClient or s.StrID = @StrID or i.EmpID=@EmpID or EnterDate =@date
go
我需要修改此部分
NameOfClient=@NameOfClient
,以便它显示以提供的字母开头的记录。因此,现在如果我想搜索
jon
我必须编写jon,但我想例如,如果我只给出
Jo
它应该返回从
Jo
开始的所有记录 我试图在
@NameOfClient
之前添加%sign,但它不起作用。你知道我怎么做吗

NameOfClient like @NameOfClient + '%'
这不管用吗


这不起作用吗?

您必须使用LIKE运算符:

WHERE NameOfClient LIKE @NameOfClient
NameOfClient like @NameOfClient+'%'

必须使用LIKE运算符:

WHERE NameOfClient LIKE @NameOfClient
NameOfClient like @NameOfClient+'%'

您需要像操作符一样使用

WHERE NameOfClient LIKE @NameOfClient
NameOfClient like @NameOfClient+'%'

您需要像
操作符一样使用

WHERE NameOfClient LIKE @NameOfClient
NameOfClient like @NameOfClient+'%'

是否可以对int字段执行相同的操作?为什么需要这样做。整数列不适用于部分匹配。你可以试试,虽然我认为它会起作用。我想让客户能够通过InnCdentis的一部分进行搜索。对int字段也可以这样做吗?你为什么需要这样做。整数列不适用于部分匹配。你可以试试,尽管我认为它会起作用。我想让客户能够按InnCentId的一部分进行搜索。你知道如何对int和date字段执行相同的操作吗?我尝试过使用like for
IncID like@IncID
,但它不起作用:)我试图让他们能够按意外事件中的第一个数字进行搜索,例如显示从5开始的所有事件购买时只提供5,例如,它将显示500501503,…对于日期和整数,您可以先将它们转换为varchar,例如:
convert(varchar(10),Date,120)
convert(varchar,intValue)
并将其与
NameOfClient
一样使用,但这会影响性能。
convert(varchar,IncID)类似于@IncID+'%'或类似于@NameOfClient+'%'的NameOfClient或convert(varchar(10),EnterDate,120)如@date+'%'
要使其工作,您需要将SP参数类型更改为varchar,因为
like
运算符仅适用于文本类型您知道如何对int和date字段执行相同的操作吗?我尝试使用like For
IncID like@IncID
但不起作用:)我正在尝试赋予它们按意外事件中的第一个数字搜索的能力示例显示从5开始的所有事件,只提供5个,例如将显示500501503…对于日期和整数,您可以首先将它们转换为varchar,例如:
convert(varchar(10),Date,120)
convert(varchar,intValue)
并将其与
NameOfClient一起使用,但这会影响性能。
转换(varchar,IncID)如@IncID+'%'或NameOfClient如@NameOfClient+'%'或转换(varchar(10),EnterDate,120)如@date+'%'
若要使其工作,您需要将SP参数类型更改为varchar,因为
like
运算符仅适用于文本类型