SQL: How to view a date range and then edit the fields in records

Posted on 2011-10-03
Last Modified: 2012-05-12
Hi Guys,

I want to run a query in sql where it finds a date range for example:

from date: 21/8/2011 to 23/9/2011

and then i want to edit the values in this date range.

Can someone please tell which query to run.

Many Thanks!
Question by:J3D1-KN1G1-1t
    LVL 75

    Assisted Solution

    by:Anthony Perkins
    SELECT * FROM YourTableNameGoesHere WHERE YourDateColumn BETWEEN '20110821' AND '20110923'

    That makes the assumption you are using a date column and not a datetime column with time other than midnight.

    Author Comment

    ok great that finds the values in the date range, how do i edit the found records?
    LVL 25

    Accepted Solution

    How you edit your records? The questions is which change and how do you want it.

    linear change

    update yourtable
    set col1 = 'x'
    where yourdate between .. and ...

    row by row
    -> cursor loop: query to select + sql code to produce the changes + update-statement to put it in database

    by application
    ->  query to find your records, show them in application where you can modify + update when changede

    Author Comment

    Cheers for the responses, I basically want to edit rows in the found set just like how you can do it via right clicking on a table and selecting "Edit top 200 rows)

    Hope that makes sense

    Many Thanks
    LVL 5

    Assisted Solution


    You can do something similar to what you want. Right click on a table and select "edit top 200 rows" (if you are on SQL Server 2008) or "open table" in SQL Server 2005. Once you get there, there is a button on the top that says "SQL"; when you click on it, it lets you write an SQL statement and you can edit the results of it if you click a cell you want to change.

    Hope its your requirement

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    759 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