| Author |
Topic |
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-03 : 14:05:27
|
Kindly help me in updating the date fileld of the table AtableA has 2 columns as values as belowA(datefrom, dateto)datefrom dateto ------------------------------------------NULL 6/8/2008NULL 14/8/2008NULL 18/8/2008 I want to update the datefrom field of table A as belowfinal out put as belowdatefrom dateto ------------------------------------------NULL 6/8/20087/8/2008 14/8/200813/8/2008 18/8/2008 either a sql query or a procedure any thingKindly help me in doing so as I am new to T-SqlThanks,aak |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-09-03 : 16:17:47
|
| Update aSet DateFrom = dateadd(month,1,(Select max(aa.DateTo) from mytable aa where aa.DateTo < a.DateTo))fromMytable a |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-04 : 00:08:49
|
quote: Originally posted by Vinnie881 Update aSet DateFrom = dateadd(month,1,(Select max(aa.DateTo) from mytable aa where aa.DateTo < a.DateTo))fromMytable a
Sorry,I misspelled the second datefrom date, instead of 15/08/2008 writing 13/08/2008. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-04 : 01:15:42
|
| [code]UPDATE aSET a.datefrom =DATEADD(d,-1,b.dateto)FROM A aCROSS APPLY(SELECT TOP 1 dateto FROM A WHERE dateto < a.dateto ORDER BY dateto DESC)b[/code] |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-04 : 03:49:24
|
quote: Originally posted by visakh16
UPDATE aSET a.datefrom =DATEADD(d,-1,b.dateto)FROM A aCROSS APPLY(SELECT TOP 1 dateto FROM A WHERE dateto < a.dateto ORDER BY dateto DESC)b
ThanksThe first column of datefrom can be null from second onwards it should show the 7/8/2008 and second value 15/8/2008.. and so on..Thanks again..The first |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-04 : 04:00:37
|
sorry it should beUPDATE aSET a.datefrom =DATEADD(d,1,b.dateto)FROM A aCROSS APPLY(SELECT TOP 1 dateto FROM A WHERE dateto < a.dateto ORDER BY dateto DESC)b |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-04 : 05:09:00
|
quote: Originally posted by visakh16 sorry it should beUPDATE aSET a.datefrom =DATEADD(d,1,b.dateto)FROM A aCROSS APPLY(SELECT TOP 1 dateto FROM A WHERE dateto < a.dateto ORDER BY dateto DESC)b
the above query is updating the same value as in dateto to datefromThanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-04 : 05:21:14
|
quote: Originally posted by aakcse
quote: Originally posted by visakh16 sorry it should beUPDATE aSET a.datefrom =DATEADD(d,1,b.dateto)FROM A aCROSS APPLY(SELECT TOP 1 dateto FROM A WHERE dateto < a.dateto ORDER BY dateto DESC)b
the above query is updating the same value as in dateto to datefromThanks.
show your actual query please. |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-04 : 06:05:19
|
| Thanks Sir, below is my query which I executed.update pset p.[pay_period_from]=dateadd(d,1,b.[pay_period_to])from payslips pcross apply(select top 1 [pay_period_to] from payslips where [pay_period_to] < p.[pay_period_to] order by [pay_period_to] desc)b |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-04 : 06:19:18
|
| thanks now its working fine, if there is any thing i will get back to youthank you so much Sir.Regards,aak |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-04 : 06:24:27
|
quote: Originally posted by aakcse thanks now its working fine, if there is any thing i will get back to youthank you so much Sir.Regards,aak
No worries. you're always welcome |
 |
|
|
|