sql server - show set of items using T-SQL CASE -


ok, know , understand have no chance explain correctly. english not ideal. i'll try. it's question t-sql case expression. have stored procedure. need display goods ids both 2 , 3 if user selects item 1. that's because item 1 contains items 2 , 3 inside, when select item 1 in drop down list, should see items 2 , 3 in results.

so, idea, user selects filter criteria, let's call item 1. if selects item 1, not real item, doesn't exist in database, drop down option must show items 2 , 3 in results.

the beginning of procedure usual, select items tables. issue belongs section. it's difficult me explain in words. can better shown in example.

where     items.item_id = @itemid or @itemid null        or items.item_id in (case       when @itemid=1 (3, 2) end))        -- here (2, 3) abstract thing, issue 

so how can display items ids 2 , 3 if parameter equals specific number, =1?

i tried this:

where     items.item_id = @itemid or @itemid null or items.item_id=(case     when @itemid=1 2     when @itemid=1 3 end)) 

but in case items latter id displayed, 3.

the issue has been resolved

i know have deleted this, i'll again: answers , please, don't downvote. understand question not clear enough, can't in other words. gave me correct answers, undersood question , has been marked answered, no need downvote -1000, don't see it? if critical , if can, me rephrase it. me upvoted answers, why downvote me??

try this

where     items.item_id = @itemid or @itemid null   or items.item_id=(case when @itemid=1 2  end )   or items.item_id=(case when @itemid=1 3  end ) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -