Ram
Ram

Reputation: 337

Find a string based on input Characters in sql

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

How to do that?

Upvotes: 3

Views: 100

Answers (2)

Amir Sherafatian
Amir Sherafatian

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

Behrad Farsi
Behrad Farsi

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

Related Questions