Reputation: 2933
I have a table
Table1
+-------+-----------+----------+
| EmpNo | FirstName | LastName |
+-------+-----------+----------+
| 123 | Bob | Smith |
| 456 | John | Smith |
| 789 | Bill | Smith |
+-------+-----------+----------+
I would like to make a stored procedure to either delete the entire table or just one entry from the table based on a parameter passed in.
Something similar to
Delete from Table1
Case where @DeleteAll = 1
Then where EmpNo is not null
Else where EmpNo = @employee
or
delete from Table1
If @DeleteAll = 1
Then where EmpNo is not null
Else
where EmpNo = @employee
select * from Table1
Upvotes: 0
Views: 129
Reputation: 10277
Try this:
IF @DeleteAll = 1
BEGIN
DELETE
FROM TABLE1
WHERE EmpNo IS NOT NULL
END
ELSE
DELETE
FROM TABLE1
WHERE EmpNo = @employee
;
Upvotes: 1