Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have following query

......
FROM [PaymentTracker1]
WHERE [Name] LIKE '%' + @SearchTerm + '%' OR @SearchTerm = ''
SELECT @RecordCount = COUNT(*)
FROM #Results....


it is searching only starting of name ,


how to search anywhere in name
Posted

1 solution

That does search anywhere in the name: '%X%' will find all rows with an 'X' anywhere in the value.
I just double checked with one of my tables:
SQL
DECLARE @SearchTerm NVARCHAR(MAX)
SET @SearchTerm = 'X'
SELECT * FROM MyTable
WHERE [Name] LIKE '%' + @SearchTerm + '%' OR @SearchTerm = ''
And it retruned exactly the results I expected.

I'd look at the rest of your query, if I was you.
 
Share this answer
 
Comments
Member 11382784 7-Jun-15 7:41am    
create PROCEDURE [dbo].[GetCustomers_Pager]
@SearchTerm VARCHAR(100) = ''
,@PageIndex INT = 1
,@PageSize INT = 10
,@RecordCount INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_NUMBER() OVER
(
ORDER BY [ID] ASC
)AS RowNumber
,[ID]
,[Name]
,[InvestmentType]
,[Amount]
,[MonthlyPay]
,[NumberOfMonths]
,[StartDate]
,[EndDate]
,[Phone]
,[Address]
INTO #Results
FROM [PaymentTracker1]
WHERE [Name] LIKE '%' + @SearchTerm + '%' OR @SearchTerm = ''
SELECT @RecordCount = COUNT(*)
FROM #Results

SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1

DROP TABLE #Results
END

OriginalGriff 7-Jun-15 8:22am    
So start by removing the WHERE clause from the final SELECT and see what you get.
Member 11382784 13-Jun-15 1:54am    
am not getting you sir..


please help
Member 11382784 13-Jun-15 4:52am    
got it sir ...
thanq
OriginalGriff 13-Jun-15 5:25am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900