SQL Server guide

Create a customer


Creates a new customer record. You can specify details such as FirstName, LastName, Email, Phone, and address fields like DefaultAddressCity and DefaultAddressCountry.

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.

INSERT INTO Customers
(FirstName, LastName, Email, Phone, Password, PasswordConfirmation, SendWelcomeEmail, MultipassIdentifier, Note, Tags, TaxExempt, TaxExemptions, DefaultAddressFirstName, DefaultAddressLastName, DefaultAddressCompany, DefaultAddressLine1, DefaultAddressLine2, DefaultAddressCity, DefaultAddressProvince, DefaultAddressCountry, DefaultAddressZip, DefaultAddressPhone, DefaultAddressName, DefaultAddressProvinceCode, DefaultAddressCountryCode, DefaultAddressCountryName)
VALUES
('John', 'Doe', 'john.doe@gmail.com', '7705553543', 'myNewP@ssword123', 'myNewP@ssword123', 1, null, 'This is a note on the customer account.', null, 0, null, 'John', 'Doe', 'John Doe Corp.', '123 Main Street', null, 'Atlanta', 'Georgia', 'United States', '30135', '7705553543', 'John Doe', 'GA', 'US', 'United States')

Using OPENQUERY in SQL Server

SELECT * FROM OPENQUERY([LS_TO_SHOPIFY_IN_GATEWAY], 'INSERT INTO Customers
(FirstName, LastName, Email, Phone, Password, PasswordConfirmation, SendWelcomeEmail, MultipassIdentifier, Note, Tags, TaxExempt, TaxExemptions, DefaultAddressFirstName, DefaultAddressLastName, DefaultAddressCompany, DefaultAddressLine1, DefaultAddressLine2, DefaultAddressCity, DefaultAddressProvince, DefaultAddressCountry, DefaultAddressZip, DefaultAddressPhone, DefaultAddressName, DefaultAddressProvinceCode, DefaultAddressCountryCode, DefaultAddressCountryName)
VALUES
(''John'', ''Doe'', ''john.doe@gmail.com'', ''7705553543'', ''myNewP@ssword123'', ''myNewP@ssword123'', 1, null, ''This is a note on the customer account.'', null, 0, null, ''John'', ''Doe'', ''John Doe Corp.'', ''123 Main Street'', null, ''Atlanta'', ''Georgia'', ''United States'', ''30135'', ''7705553543'', ''John Doe'', ''GA'', ''US'', ''United States'')')

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_SHOPIFY_IN_GATEWAY] syntax.

DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO Customers
(FirstName, LastName, Email, Phone, Password, PasswordConfirmation, SendWelcomeEmail, MultipassIdentifier, Note, Tags, TaxExempt, TaxExemptions, DefaultAddressFirstName, DefaultAddressLastName, DefaultAddressCompany, DefaultAddressLine1, DefaultAddressLine2, DefaultAddressCity, DefaultAddressProvince, DefaultAddressCountry, DefaultAddressZip, DefaultAddressPhone, DefaultAddressName, DefaultAddressProvinceCode, DefaultAddressCountryCode, DefaultAddressCountryName)
VALUES
(''John'', ''Doe'', ''john.doe@gmail.com'', ''7705553543'', ''myNewP@ssword123'', ''myNewP@ssword123'', 1, null, ''This is a note on the customer account.'', null, 0, null, ''John'', ''Doe'', ''John Doe Corp.'', ''123 Main Street'', null, ''Atlanta'', ''Georgia'', ''United States'', ''30135'', ''7705553543'', ''John Doe'', ''GA'', ''US'', ''United States'')'
EXEC (@MyQuery) AT [LS_TO_SHOPIFY_IN_GATEWAY]