?
Solved

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

Posted on 2011-10-03
5
Medium Priority
?
345 Views
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!
0
Comment
Question by:J3D1-KN1G1-1t
5 Comments
 
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.
0
 

Author Comment

by:J3D1-KN1G1-1t
ID: 36907398
ok great that finds the values in the date range, how do i edit the found records?
0
 
LVL 25

Accepted Solution

by:
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
0
 

Author Comment

by:J3D1-KN1G1-1t
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
0
 
LVL 5

Assisted Solution

by:AlokJain0412
AlokJain0412 earned 668 total points
ID: 36914882
Hi

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
0

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