SixPapaCharlie
May the force be with you
- Joined
- Aug 8, 2013
- Messages
- 16,414
- Display Name
Display name:
Sixer
I have 3 variables passed into a stored proc.
They are all optional and integers that are defaulted to 0 in the proc so I know if they were passed in.
A, B, C
I want to select data using only the positive (passed in) variables
select * from some table
where if A > 0 then Field1 = A
AND
If B > 0 then Field2 = B
AND
If C > then Field3 = C
So if the user doesn't pass in B, it will not constrain the selected data.
I can't seem to figure out that syntax in the where clause.
I was going to build dynamic SQL but I think that is sloppy.
What say the nerds?
They are all optional and integers that are defaulted to 0 in the proc so I know if they were passed in.
A, B, C
I want to select data using only the positive (passed in) variables
select * from some table
where if A > 0 then Field1 = A
AND
If B > 0 then Field2 = B
AND
If C > then Field3 = C
So if the user doesn't pass in B, it will not constrain the selected data.
I can't seem to figure out that syntax in the where clause.
I was going to build dynamic SQL but I think that is sloppy.
What say the nerds?