wildcard in SQLDataSource WHERE clause to show all results

Squirrel

New Member
How can i have a wildcard in a where clause to where it will show ALL in a certain situation?I have a dropdown list that contains:
  • All - (no value)
  • Staff (value = http://stackoverflow.com/questions/12643165/Staff)
  • Manager (value = http://stackoverflow.com/questions/12643165/Manager)
  • Distributor (value = http://stackoverflow.com/questions/12643165/Distributor)
My SQL select statement originally was:\[code\]SELECT * FROM [DB_Table] WHERE ([Site] = @Site) AND (RoleType=@RoleType)\[/code\]The Role Type equals either Staff, Manager or Distributor and is never blank. This works great to filter by each of the 3 roles, but how can i make it so when ALL is selected, it shows all instead?I believe i need to do something like this, but can't get it right:\[code\]SELECT * FROM [DB_Table] WHERE ([Site] = @Site) AND (RoleType=@RoleType OR @RoleType <> NULL)\[/code\]ANSWER: I couldn't leave the DDL value for ALL empty, so this is what it looks like and works now.\[code\]<asp:ListItem Text="All" Value="http://stackoverflow.com/questions/12643165/All" Selected="True"></asp:ListItem><asp:ListItem Text="Staff" Value="http://stackoverflow.com/questions/12643165/Staff"></asp:ListItem><asp:ListItem Text="Manager" Value="http://stackoverflow.com/questions/12643165/Manager"></asp:ListItem><asp:ListItem Text="Distributor" Value="http://stackoverflow.com/questions/12643165/Distributor"></asp:ListItem>SELECT * FROM [DB_Table] WHERE ([Site] = @Site) AND (RoleType=@RoleType OR @RoleType = 'ALL')\[/code\]
 
Back
Top