SQL Query to get results along with the parameter -Useful in SSRS as Dropdown Seperator

Posted: February 23, 2010 in SQL, SSRS

I was working on a SSRS report having two dropdown controls State & District which behaves as a parent -child dropdown.

My table looks like

State1 District1
State1 District2
State1 District3
State1 District4
State2 District5
State2 District6
State2 District7


And when I select State from the first Drop Down, I need the District drop down to be populated with values

~~State1~~

District1

District2

District3

~~State2~~

District4

District5

District6

District7


This way user will come to know which state the district’s belong to.To do this I used the following query.


(select [State],District from dbo.T_TownSnapshot where state in (@State)

union

select [state], ‘~~’ + state + ‘~~’ as District from dbo.T_TownSnapshot where state in (@State))

Advertisements
Comments
  1. sunlikestar says:

    you forgot the order by clause.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s