Find string based on character input in sql

How to find string based on input characters in sql?

For instance:

Table 1 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 it?

+3
source share
2 answers

Follow this code:

SELECT * FROM table WHERE field like '%d%' AND field like '%h%' AND field like '%o%' 

I mean, you must surround every character of the input string%.

+1
source

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 request may look 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
0
source

All Articles