Archive for June, 2007

Using While Statements inside MSSQL Stored Procedures 

This was a bit more complicated than the IF statements, but extremely useful.  I was able to
Procedure [dbo].[deleteParticipant]
@ParticipantID int
as
– Declare the variables to store the values returned by FETCH.
DECLARE @GroupID int
DECLARE group_cursor CURSOR FOR
SELECT GroupID FROM Participants
WHERE ParticipantID = @ParticipantID
OPEN county_cursor
– Perform the first fetch and store the values in variables.
– Note: The variables are […]

Using If Statements inside MSSQL Stored Procedures 

Adding IF statements to a MSSQL Stored Procedure can help make a query more dynamic. For instance, if we had are deleting a participants from a group and wanted to remove a group after the last person was removed, we would do the following:
DELETE FROM Participants
WHERE ParticipantID = @ParticipantID AND GroupID = @GroupID
IF […]