Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Update dates as per the COLUMNS

Author  Topic 

sql_server_dba
Posting Yak Master

167 Posts

Posted - 2012-02-16 : 20:42:28
Experts..need some input here

My code works fine but couple of months back it got messed up and i did not cleaned the data properly. So any help would be aprecieated..

I have a table with 4 columns A(INTEGER), B(DateTime), C(Integer), D(DateTime).

So now here is how my data should look like....

A B C D
101 01-09-2010 1 02-11-2010
101 02-11-2010 1 03-30-2010
101 03-30-2010 1 12-15-2010
101 12-15-2010 1 03-12-2011
101 03-12-2011 1 12-01-2011
101 12-01-2011 1 01-01-9999
102 01-23-2011 4 08-23-2011
102 08-23-2011 4 12-01-2011
102 12-01-2011 4 01-01-9999


But my data is messed up like

A B C D
101 01-09-2010 1 03-30-2010
101 02-11-2010 1 03-30-2010
101 03-30-2010 1 12-15-2010
101 03-30-2010 1 03-12-2011
101 03-12-2011 1 12-01-2011
101 12-01-2011 1 01-01-9999


How can i write the code to match up the data in it? I am not a great developer, so i have no idea about how to fix this. Any help would be really great!!!!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-16 : 20:58:42
firstly can you explain how to get from the messed data to the data you want ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sql_server_dba
Posting Yak Master

167 Posts

Posted - 2012-02-17 : 11:51:15
I thought i already explained that. Sorry if i am not so clear...

here is the messed up data..
A B C D
101 01-09-2010 1 03-30-2010
101 02-11-2010 1 03-30-2010
101 03-30-2010 1 12-15-2010
101 03-30-2010 1 03-12-2011
101 03-12-2011 1 12-01-2011
101 12-01-2011 1 01-01-9999

and here is the required format...
A B C D
101 01-09-2010 1 02-11-2010
101 02-11-2010 1 03-30-2010
101 03-30-2010 1 12-15-2010
101 12-15-2010 1 03-12-2011
101 03-12-2011 1 12-01-2011
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-17 : 11:57:59
you need to use your words....

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sql_server_dba
Posting Yak Master

167 Posts

Posted - 2012-02-18 : 16:49:02
OK...The date in column B of row2 should be same as the date value of Column D in record 1. Similarly, the date value in row 3 should start with the data value of column D in row 2 and it continues and the date value of column D in the last row should be 01-01-9999.
Go to Top of Page
   

- Advertisement -