开发者

How to select only those rows which contain only substring of input's parameter

I have a table in MSSQL that has several columns. It looks as follows:

col1| col2 | col3

------------------

HSP | full | ""

HSP | full | "UE"

HSP | min | ""

HSP | min | "PS"

CC | full | "UE"

My select query has 2 parameters, which receives from web app:

@col2 = { full, min }

@col3 = e.g. "PE+UE+STR" or "PE" or "" (in general - combination of different abbreviations or none)

All i want to do is to select only those rows, which contain the appropriate abbreviation. e.g. if the input is

开发者_高级运维@col2 = "full"

@col3 = "PE+UE+STR"

output:

HSP | full | "UE"

CC | full | "UE"

if @col3 = "", the output would be:

HSP | full | ""

HSP | min | ""

Thanks for any help.

Marcin


Now I might be totally off, but I remember there being a LIKE keyword in SQL.

SELECT * from table WHERE col3 LIKE pattern

where pattern is what you want to compare with. You might need to parse the parameter to convert into .... WHERE col3 LIKE pattern1 OR col3 LIKE pattern2 or something perhaps?

If this is totally off, please comment.


you want: WHERE '+' + @col3 + '+' like '%+' + col3 + '+%'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜