Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Data in date column to decrement with one


Data in date column to decrement with one

Author
Message
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9027 Visits: 19036
asifejaz (7/8/2013)
Thanks for your help. Really appreciate that. I dragged in the project that is at its end before go live..
I ran the script and the out put that appears in last column after delta2 starting from 2013-10-15
and goes down decrementing by 1 day is the requirement

delta2 (No column name)
-1 15/10/2013
-2 14/10/2013
-3 13/10/2013
-4 12/10/2013
-5 11/10/2013

it keep on decrementing the accrualdate till the last record.
apologies if it is still not clear Sad hope this help you .


Which columns make up your primary key?


WITH Updater AS (
SELECT
[PK list], -- replace this with your list of columns in the composite PK
[AccrualDate],
[NewAccrualDate] = DATEADD(d,0-ROW_NUMBER() OVER(ORDER BY [AccrualDate] DESC),AccrualDate)
FROM SampleData
)
UPDATE Updater SET [AccrualDate] = [NewAccrualDate]



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
asifejaz
asifejaz
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 356
thanks. Sorry i didnt understand what you mean by this

WITH Updater AS (


pls let me know.
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9027 Visits: 19036
asifejaz (7/10/2013)
thanks. Sorry i didnt understand what you mean by this

WITH Updater AS (


pls let me know.




That's a Common Table Expression, a CTE. How long have you been working with SQL Server 2005?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
asifejaz
asifejaz
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 356
8 months.Angry
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9027 Visits: 19036
asifejaz (7/12/2013)
8 months.Angry


Don't worry, you'll get the hang of it - quicker, if you can attract the attention of someone here on ssc who's in your time zone :-D
Any questions about the proposed solution? Just ask.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
asifejaz
asifejaz
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 356
the resolution didnt solve it.

it decrement the first row successfully. when moving to second row instead of decrementing it to one it decrements it to two , then to third row it decrements by three. e.g.

actual data to changed data
2013-06-31 to 2013-06-30
2013-06-29 to 2013-06-27
2013-06-25 to 2013-06-21

where as the requirement is to decrement each one by one only.
like
actual data to changed data
2013-06-31 to 2013-06-30
2013-06-29 to 2013-06-28
2013-06-25 to 2013-06-24

i hope you understand..
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9027 Visits: 19036
asifejaz (7/12/2013)
the resolution didnt solve it.

it decrement the first row successfully. when moving to second row instead of decrementing it to one it decrements it to two , then to third row it decrements by three. e.g.

actual data to changed data
2013-06-31 to 2013-06-30
2013-06-29 to 2013-06-27
2013-06-25 to 2013-06-21

where as the requirement is to decrement each one by one only.
like
actual data to changed data
2013-06-31 to 2013-06-30
2013-06-29 to 2013-06-28
2013-06-25 to 2013-06-24

i hope you understand..


Isn't this exactly the same as the solution posted by Andrew G, second post on this thread, subtract a day from each date?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search