我創建了一個按姓氏返回申請人列表的過程。我有一個問題,搜索姓有撇號的申請人(例如O'Connor)。你能幫尋找那些申請人:將撇號添加到姓氏搜索
下面是我的查詢碼:
if Rtrim(@FirstName) <> ''
begin
If(Len(@FirstName) < 30) and (CharIndex('%', @FirstName) = 0) and @FirstName != ''
Set @FirstName = char(39) + @FirstName + '%' + char(39)
end
if Rtrim(@LastName) <> ''
begin
If(Len(@LastName) < 60) and (CharIndex('%', @LastName) = 0) and @LastName != ''
Set @LastName = Char(39) + @LastName + '%' + char(39)
end
#At the end - --Now build dinamically the filter base on input parameters
if Rtrim(@FirstName) <> ''
select @Where = @Where + ' and a.FirstName like '+ Rtrim(@FirstName)
if Rtrim(@LastName) <> ''
select @Where = @Where + ' and a.LastName like '+ Rtrim(@LastName)
你究竟在做什麼*做*?您似乎在構建動態SQL字符串,但*爲什麼*?此外,還有更好更安全的方法來處理動態SQL。 – Tomalak