Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem With BatchId In Query
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Problem With BatchId In Query
Miscellaneous
Thread ID:
01451323
Message ID:
01451323
Views:
99
In this proc I pass in 0 or a BatchId from a previous run. If a batchId is passed, I want to use it, otherwise, compute the next
batch Id and use that.

This is alwats incrementing the batch Id. I don't see what's wrong.
CREATE PROCEDURE ap_AddInventoryRecord
	@PartId			INT = NULL,	
	@WarehouseId	INT = NULL,
	@LocationId		INT = NULL,
	@UserId			INT = NULL,
	@SerialNo		VARCHAR(30) = NULL,
	@Quantity		INT = 1,
	@DropShip		TINYINT = NULL,
	@Printed		TINYINT = NULL,
	@ActionDate		DATETIME = NULL,
	@PurchaseOrder	VARCHAR(30) = NULL,
 	@Comments		TEXT = NULL,
	@InventoryId	INT = NULL OUTPUT,
	@BatchId		INT OUTPUT

AS
BEGIN

	IF @ActionDate IS NULL
		BEGIN
			SET @ActionDate = GETDATE()
		END

	IF(@BatchId IS NULL OR @BatchId = 0)
		BEGIN
			SELECT @BatchId = MAX(BatchId) + 1 FROM Inventory
		END

	IF(@BatchId IS NULL)
		BEGIN
			SET @BatchId = 1
		END

	INSERT INTO Inventory
		(BatchId, PartId, WarehouseId, LocationId, UserId, SerialNo, Quantity,
		DropShip, Printed, ActionDate, PurchaseOrder, Comments)
		VALUES
		(@BatchId, @PartId, @WarehouseId, @LocationId, @UserId, @SerialNo, @Quantity, 
		@DropShip, @Printed, @ActionDate, @PurchaseOrder, @Comments)
	
	SET @InventoryId = SCOPE_IDENTITY()

END
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform