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

Posted on 2011-10-03
Medium Priority
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
Anthony Perkins earned 664 total points
ID: 36907171
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

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

Accepted Solution

jogos earned 668 total points
ID: 36908534
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

ID: 36914365
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

Assisted Solution

AlokJain0412 earned 668 total points
ID: 36914882

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

839 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