Solved

Incorrect syntax near '='.

Posted on 2014-09-27
3
129 Views
Last Modified: 2014-09-27
I am trying to change occurences of 'NULL' in field ShippingAddressId to value 1
I get the following error:Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '='.
The code I have is below:
Thanks in advance for any help given.
USE [CorpWear265_Restore_TestAlt]
UPDATE dbo.[Order] SET ShippingAddressId =  CASE WHEN ShippingAddressId IS NULL THEN ShippingAddressId = 1
END
SELECT TOP 4000 [Id]
	  ,[OrderGuid]
      ,[CustomerId]
      ,[BillingAddressId]
      ,[ShippingAddressId]
      ,[OrderStatusId]
      ,[ShippingStatusId]
      ,[PaymentStatusId]
      ,[PaymentMethodSystemName]
      ,[CustomerCurrencyCode]
      ,[CurrencyRate]
      ,[CustomerTaxDisplayTypeId]
      ,[VatNumber]
      ,[OrderSubtotalInclTax]
      ,[OrderSubtotalExclTax]
      ,[OrderSubTotalDiscountInclTax]
      ,[OrderSubTotalDiscountExclTax]
      ,[OrderShippingInclTax]
      ,[OrderShippingExclTax]
      ,[PaymentMethodAdditionalFeeInclTax]
      ,[PaymentMethodAdditionalFeeExclTax]
      ,[TaxRates]
      ,[OrderTax]
      ,[OrderDiscount]
      ,[OrderTotal]
      ,[RefundedAmount]
      ,[RewardPointsWereAdded]
      ,[CheckoutAttributeDescription]
      ,[CheckoutAttributesXml]
      ,[CustomerLanguageId]
      ,[AffiliateId]
      ,[CustomerIp]
      ,[AllowStoringCreditCardNumber]
      ,[CardType]
      ,[CardName]
      ,[CardNumber]
      ,[MaskedCreditCardNumber]
      ,[CardCvv2]
      ,[CardExpirationMonth]
      ,[CardExpirationYear]
      ,[AuthorizationTransactionId]
      ,[AuthorizationTransactionCode]
      ,[AuthorizationTransactionResult]
      ,[CaptureTransactionId]
      ,[CaptureTransactionResult]
      ,[SubscriptionTransactionId]
      ,[PurchaseOrderNumber]
      ,[PaidDateUtc]
      ,[ShippingMethod]
      ,[ShippingRateComputationMethodSystemName]
      ,[Deleted]
      ,[CreatedOnUtc]
      ,[ShippedDateUtc]
      ,[DeliveryDateUtc]
      ,[OrderWeight]
      ,[TrackingNumber]
      ,[OrderEnquiry]
FROM [CorpWear265_Restore_TestAlt].[dbo].[Order]

Open in new window

0
Comment
Question by:homeshopper
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40347328
I would suggest:

UPDATE dbo.[Order]
SET ShippingAddressId =  1
WHERE  ShippingAddressId IS NULL
;

but the error was the case expression which should have been:

CASE WHEN ShippingAddressId IS NULL THEN 1 END
0
 

Author Comment

by:homeshopper
ID: 40347341
Thank you for your suggestion, that works.
Now I wanted to assign ShippingAddress to CustomerId value when it is Null.
I get the following error:The UPDATE statement conflicted with the FOREIGN KEY constraint
The new code I have is:
UPDATE dbo.[Order]
SET ShippingAddressId =  CustomerId
WHERE  ShippingAddressId IS NULL
Thanks for the help.
0
 

Author Closing Comment

by:homeshopper
ID: 40347352
Thankyou for the suggestion, I got the second query to work using the following:
ALTER TABLE dbo.[Order] NOCHECK CONSTRAINT ALL
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Upgrading an old legacy SQL server 20082 to 2014 - TSQL compatibility 3 41
triggered use of sp_send_dbmail failure 2 23
Max Consumption Rate (MCR) 3 34
TSQL previous 5 24
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now