Solved

Incorrect syntax near '='.

Posted on 2014-09-27
3
133 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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