SQL Server guide

Update a product


Updates an existing product record in the Products table. This example demonstrates updating multiple fields, including images and dimensions. Note that supplying image fields will reset any previously existing images for the product.

Standard SQL query example

This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.

UPDATE Products
SET   [Name]='SSIS PowerPack 3 - Updated'
	, [Caption]='Caption-updated'
	, [Description]='Desc-updated'
	--, [UnitLabel] --only when product type=service
	, [Active]='true'
	, [PackageDimensionsHeight]=12
	, [PackageDimensionsWidth]=13
	, [PackageDimensionsLength]=14
	, [PackageDimensionsWeight]=1122
	, [URL]='https://zappysys.com/products/ssis-powerpack/?updated=1'
	, [Image1]='https://zappysys.com/images/tech/web-api-logo.png?updated=1'
	, [Image2]='https://zappysys.com/images/tech/xml-logo.png?updated=1'
	WHERE Id='prod_MiSJzGZ8PDM9uh'

Using OPENQUERY in SQL Server

SELECT * FROM OPENQUERY([LS_TO_STRIPE_IN_GATEWAY], 'UPDATE Products
SET   [Name]=''SSIS PowerPack 3 - Updated''
	, [Caption]=''Caption-updated''
	, [Description]=''Desc-updated''
	--, [UnitLabel] --only when product type=service
	, [Active]=''true''
	, [PackageDimensionsHeight]=12
	, [PackageDimensionsWidth]=13
	, [PackageDimensionsLength]=14
	, [PackageDimensionsWeight]=1122
	, [URL]=''https://zappysys.com/products/ssis-powerpack/?updated=1''
	, [Image1]=''https://zappysys.com/images/tech/web-api-logo.png?updated=1''
	, [Image2]=''https://zappysys.com/images/tech/xml-logo.png?updated=1''
	WHERE Id=''prod_MiSJzGZ8PDM9uh''')

Using EXEC in SQL Server (handling larger SQL text)

The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements. This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).

Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_STRIPE_IN_GATEWAY] syntax.

DECLARE @MyQuery NVARCHAR(MAX) = 'UPDATE Products
SET   [Name]=''SSIS PowerPack 3 - Updated''
	, [Caption]=''Caption-updated''
	, [Description]=''Desc-updated''
	--, [UnitLabel] --only when product type=service
	, [Active]=''true''
	, [PackageDimensionsHeight]=12
	, [PackageDimensionsWidth]=13
	, [PackageDimensionsLength]=14
	, [PackageDimensionsWeight]=1122
	, [URL]=''https://zappysys.com/products/ssis-powerpack/?updated=1''
	, [Image1]=''https://zappysys.com/images/tech/web-api-logo.png?updated=1''
	, [Image2]=''https://zappysys.com/images/tech/xml-logo.png?updated=1''
	WHERE Id=''prod_MiSJzGZ8PDM9uh'''
EXEC (@MyQuery) AT [LS_TO_STRIPE_IN_GATEWAY]