question

SSGC avatar image
SSGC asked

one or all for multiple perameters

we have three tables: country,team, player. a report want to let people can choose all country or one, all team or one and all player or one. how we should do query to achieved this? for example like: select c.country,t.team,p.player from country c join team t on t.tid=c.tid join player p on p.pid = t.pid where c.country =@country and t.team = @team and p.player = @player it will give us results for only one not all of the country or all of team of all of players. Thank you for your help!
sql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
sabinweb avatar image
sabinweb answered
How do you send ,from application, the value of the `@country` param in case of `all countries` ? - if like text 'all countries' then you can use something like this: `c.country = ISNULL(NULLIF(@country,'all countries'),c.country)` - if Null value , then: `c.country = ISNULL(@country,c.country)` - other case : need research.
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

SSGC avatar image SSGC commented ·
app will send '~ALL'. I think your code may be a best way to approach. I read the link, it works too. thx.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.