Link to home
Create AccountLog in
Avatar of scm0sml
scm0sml

asked on

Different statements in my where clause

If you look at the statement below, you can see I am having to have a number of select statements depedning on certain variable values.

I'm just wondering is there a better way to do this with maybe one statement that could include case statements etc in the where clause?

If someone could "translate" my example to include this that would be great.
IF @DeptStr = ''
		BEGIN
			IF @UserDept <> 'WHOLESALE'
			BEGIN 
				SELECT * FROM #TEMP_APPROVED_ORDERS WHERE Cat <> 995
			END
			ELSE
			BEGIN
				SELECT * FROM #TEMP_APPROVED_ORDERS WHERE Cat = 995
			END
		END
		ELSE
		BEGIN
			IF @UserDept <> 'WHOLESALE'
			BEGIN 
				SELECT * FROM #TEMP_APPROVED_ORDERS WHERE Cat <> 995 
				AND Dept in (@DeptStr)
			END
			ELSE
			BEGIN
				SELECT * FROM #TEMP_APPROVED_ORDERS WHERE Cat = 995 
				AND Dept in (@DeptStr)
			END
		END

Open in new window

SOLUTION
Avatar of Neil Russell
Neil Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account