Solved

Incorrect syntax near '='.

Posted on 2014-09-27
3
127 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thankyou for the suggestion, I got the second query to work using the following:
ALTER TABLE dbo.[Order] NOCHECK CONSTRAINT ALL
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

11 Experts available now in Live!

Get 1:1 Help Now