I am working on a query whose where clause varies depending on a BIT value.
I hope not. We do not use BIT flags in a declarative language like SQL; that was 1960's assembly language! But more than that, read any book on Software Engineering. This is called “flag coupling” and it is the worst way to write code in any language. We make fun of this with the phrase “Automobiles, Squids and Lady Gaga” code. Did you read Yourdon, DeMarco, et al or anything about Software Engineering in school?
Google coupling and cohesion.
Basically, I am listing stock records [sic: rows are not records] and if @Include_Accessories = 1 then I want to list ALL stock records [sic] but if set to 0 then I want to exclude stock belonging to Stock_Group D.<<
Why don't You know that a rows is not a record? That is the first week of an SQ class when they discuss the basic concepts of RDBMS.
Also, where is the DDL? This is minimal Netiquette in SQL forums. What you posted is garbage, without any keys, constraints, etc.
A variable length stock number is a bad design and a NULL-able stock number is insane. You should be using an industry standard code if possible (EAN, GTIN, UPC, etc).
Think about how silly VARCHAR(1) is.
CREATE TABLE Stock
(stock_nbr CHAR(4) NOT NULL PRIMARY KEY,
CHECK (stock_nbr LIKE 'A[0-9][0-9][0-9]'),
stock_grp CHAR(1) NOT NULL
CHECK (stock_grp LIKE '[A-Z]')
)
See how we have a key and use constraints in SQL? Here is the ANSI/ISO Standard insertion syntax that T-SQ has had for a long; there is no need to use the old Sybase stuff today
INSERT INTO Stock
VALUES ('A001', 'A'),
('A002', 'A'),
('A003', 'B'),
('A004', 'B'),
('A005', 'B'),
('A006', 'C'),
('A007', 'C'),
('A008', 'D');
Now write two views. Think in sets, not procedures.
CREATE VIEW All_Stock
AS
SELECT stock_nbr, stock_grp
FROM Stock;
CREATE VIEW Non_Accessories_Stock
AS
SELECT stock_nbr, stock_grp
FROM Stock
WHERE stock_grp <> 'D';