spupdateinventory.sql

来自「微软的行业应用解决方案示例」· SQL 代码 · 共 46 行

SQL
46
字号
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE spUpdateInventory
	@Name VarChar(100),
	@Picture Image,
	@Price Money,
	@InStock Int,
	@DistributionCenter Int,
	@Bin Int,
	@InventoryId Int,
	@sync_last_received_anchor Int,
	@sync_row_count Int Output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	--update only if last cyns received is greater than or equal the row's version
	UPDATE [Inventory]
	SET 
		[Name] = @Name
		,[Picture] = @Picture
		,[Price] = @Price
		,[InStock] = @InStock
		,[DistributionCenter] = @DistributionCenter
		,[Bin] = @Bin
	FROM Inventory I
	WHERE I.InventoryId = @InventoryId	
	AND	@sync_last_received_anchor >= 
						ISNULL(
								(SELECT CT.SYS_CHANGE_VERSION 
								FROM CHANGETABLE(VERSION Inventory, (InventoryId), (I.InventoryId)) AS CT),
							0)

     SET @sync_row_count = @@ROWCOUNT;
END
GO

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?