Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:55:05+00:00 2026-05-31T02:55:05+00:00

I’m trying to write an UPDATE SQL Query to clean up my database a

  • 0

I’m trying to write an UPDATE SQL Query to clean up my database a bit…

Here’s what I’ve tried but it did create huge problems for me and ended up not honoring all of my WHEREs which changed records that weren’t supposed to be changed…

UPDATE Orders
SET Orders.OrderStatus = Cancelled
WHERE Orders.OrderStatus in (New,Pending,Processing,Payment Declined,Awaiting Payment,See Line Items,See Order Notes,Backordered)
AND Orders.Total_Payment_Received = 0

There was also a third clause. That clause did not work as well, it was designed to get all records older than sixty days, it looked like it wouldn’t work and I’m not sure why I executed the code. I’m afraid to post that line here cause I’ll look dumb. It was something like:

AND Orders.OrderDate BETWEEN DATEADD(Day, -60, GetDate())

So only records with OrderDate older than sixty days should be affected.

If anybody can help me compile a query that would work it’d be greatly appreciated…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:55:06+00:00Added an answer on May 31, 2026 at 2:55 am

    I’m not completely sure if you’re saying the first update is working or not, or if it’s just the order date check that was causing problems, so I’ll just address the order date.

    If you want records older than 60 days…

    and Orders.OrderDate < dateadd(day, -60, getdate())
    

    However, since getdate() includes time, you likely want to take that out of consideration…

    and Orders.OrderDate < dateadd(day, -60, convert(char(10), getdate(), 101))
    

    The convert function in this case removes the time part of the date.

    Also, if your order statuses are supposed to be strings then they need to be surrounded by quotes, so your full query would look like this:

    UPDATE Orders 
    SET Orders.OrderStatus = 'Cancelled'
    WHERE Orders.OrderStatus in ('New','Pending','Processing','Payment Declined','Awaiting Payment','See Line Items','See Order Notes','Backordered') 
    AND Orders.Total_Payment_Received = 0 
    AND Orders.OrderDate < dateadd(day, -60, convert(char(10), getdate(), 101))
    

    A word of advice on running updates. ALWAYS run a SELECT first with the same WHERE clause so you can identify which rows are going to be affected. This will save you a lot of pain. If there are too many rows that need to be updated, use SELECT TOP 5000 or something so you can at least check some of them. Always know exactly what you’re going to update before you update it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.