Sorry all, I should have been more careful before posting. The solution =
requires two elements, and I captured each one of the them in each of my =
previous posts, but not both together...
This **will** work (promise, scouts' honor):
--Assume a bit variable @Saved
SELECT blah
FROM blah
WHERE ISNULL(MyBitColumnName, 0) =3D CASE @Saved
WHEN 1 THEN 1=20
ELSE ISNULL(MyBitColumnName, 0)
END
Basically, what the above does is...
1. If @Saved =3D 1, compare column value to 1 (no problem)
2. Otherwise, compare the column value to the column value. Since a =
column's value always equals itself (except when Null), comparing the =
MyBitColumnColumn to itself will take care of the 1s and 0s. Using =
ISNULL takes care of the Nulls.
Hth,
John Barone
[quoted text, click to view] "John V. Barone" <nogospam_baronej_2000@yahoo.com> wrote in message =
news:O2cNBc3PDHA.3192@tk2msftngp13.phx.gbl...
Sorry, I misread your original note in my first reply, which will =
return only 0 or Nulls (and not all records), if @Saved =3D 0.
Instead, try:
--Assume a bit variable @Saved
SELECT blah
FROM blah
WHERE MyBitColumnName =3D CASE @Saved =20
WHEN 1 THEN 1=20
ELSE MyBitColumnName=20
END
Basically, what the above does is...
1. If @Saved =3D 1, compare column value to 1 (no problem)
2. Otherwise, compare the column value to the column value. Since a =
column values always equals itself (even if Null), all the records will =
be returned. (BTW, this is trick I use to allow multiple parameter =
searches in a single sproc.)
Hth,
John Barone
[quoted text, click to view] "Bob Twickler" <twick10@hotmail.com> wrote in message =
news:OGdmZA2PDHA.3088@TK2MSFTNGP10.phx.gbl...
> I am trying to run a SQL procedure that will return either a bit =
=3D true or
> bit =3D true, false or NULL.
>=20
> Does anybody know the WHERE Statement that will return any values =
including
> possible NULL values.
>=20
> What I want is if "@Saved" =3D 1 (true),,, return only Saved =3D 1;
> if @Saved =3D 0 (false),,,, return all records.
> In other words retrun all records (including NULLS) if @Saved is 0 =
(False)
>=20
> I have tried
>=20
> Where Saved =3D CASE @Saved =3D 1 THEN 1 ELSE ?????? END
>=20
> What would ??????? be to return all records.
>=20
> I hope someone will show me how simple this is.
>=20
> Bob
>=20