I'm working with SQL Server 2005 on a stored procedure, but it appears to be going through both parts of the following statement, and not skipping the second half if it is supposed to.

Basically it should update the row if there is data there, and remove the row if there isn't.
All the fields except for the ID fields are from user input (or a lack thereof).

DECLARE @PartID1 char(10)
	If @PartDescription1 IS NOT NULL AND @PartCost1 IS NOT NULL
		Update PART
		Set PartDescription = @PartDescription1, PartCost = @PartCost1, PartCharge = @PartCharge1, OrderedFrom = @PartOrderedFrom1, OrderNumber = @PartOrderNumber1
		Where ID = @PrtID1
	Else
		If @PrtID1 IS NOT NULL AND @PartDescription1 IS NULL
			Delete From PROBLEM_PART Where PROBLEM_ID = @ProblemID AND PART_ID = @PrtID1
			Delete From PART Where ID = @PrtID1
	Select @PartID1=@PrtID1

Thank you,
J'Tok

I figured it out. blocks need to be wrapped in BEGIN/END.

Here is is:

DECLARE @PartID1 char(10)
	If @PartDescription1 IS NOT NULL AND @PartCost1 IS NOT NULL
BEGIN
		Update PART
		Set PartDescription = @PartDescription1, PartCost = @PartCost1, PartCharge = @PartCharge1, OrderedFrom = @PartOrderedFrom1, OrderNumber = @PartOrderNumber1
		Where ID = @PrtID1
END
	Else If @PrtID1 IS NOT NULL AND @PartDescription1 IS NULL
BEGIN
			Delete From PROBLEM_PART Where PROBLEM_ID = @ProblemID AND PART_ID = @PrtID1
			Delete From PART Where ID = @PrtID1
END
	Select @PartID1=@PrtID1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.