Reputation: 337
How to find a string based on input characters in sql?
For example:
Table1 column name: desc
data warehousing
sql serverl
c#.Net
asp.net
My input: @FindString='dho'
should return 'data warehousing'
My input: @FindString='sv'
should return 'sql serverl'
My input: @FindString='aep'
should return 'asp.net'
How to do that?
Upvotes: 3
Views: 100
Reputation: 2083
i think you want this :
declare @inputString nvarchar(max) = 'eap';
declare @where nvarchar(max) =
case @inputString
when 'dho' then 'data warehousing'
when 'sv' then 'sql serverl'
when 'eap' then 'asp.net'
else ''
end
select * from Table1
where desc = @where
also your query can be like this:
declare @inputString nvarchar(max) = 'dho'
select * from
(select
case [desc]
when 'data warehousing' then 'dho'
when 'sql serverl' then 'sv'
when 'asp.net' then 'aep'
else ''
end
as [newDesc]
from [table])t
where newDesc = @inputString
Upvotes: 0
Reputation: 1110
Go with this code:
SELECT * FROM table WHERE field like '%d%' AND field like '%h%' AND field like '%o%'
I mean you should surround each character of input string with %.
Upvotes: 1