not until i understand what you're doing with those variables, and that will require that i understand your table relationships

start 'splainin, lucy...

OK, i'll start with the basics and go from there!

Every Priority is linked to a town, a town linked to a sector and a sector to a division (vStructure is a view joining the town, sector and division info together to save me having to keep doing it :))

I want to be able to able to find a count of each priorities.status for a given area - ie for a town, all the towns in a sector or all the towns within a division.

Does that help (and my name's not Lucy...........actually, you've been so helpful you can call me what you want )

if the view contains only inner joins, you're okay using it, otherwise all bets are off

obviously the @TownID and other values are being set by your application language, so you should use your application language to decide which AND condition to include in your query, so leave the ISNULL stuff out

1) it did - now it doesn't 2) Not sure what you mean. As I understand it, my c# code calls the procedure and passes the variable the procedure requires. If I don't want to use the variable I still need to pass a NULL value. How do I get my c# code to decide which AND statements are used in a SQL procedure?

I thought that might be what you meant. We try to avoid adding sql code to our applications where ever possible, preferring to use procedures. This is to allow sql people to work with all neccessary code independantly of app code.