0
id date-of-birth
001 01/01/2011 'dd/mm/yyyy'
002 05/01/2012
003 15/05/2009
....
從上面的表格,我想從計算天數日期的聯接列,日期的出生應該從當年驗證。
查找的時間差查詢
Select id, DATEDIFF(dd,Convert(datetime, date-of-join, 103),getdate())
上面的查詢從日期的聯接工作,但二要驗證的日期的,加入這樣的...
例如
id date-of-birth no-of-days
001 01/01/2011 64
002 05/01/2012 60
003 15/05/2009 295
....
條件
For 001, date-of-birth is '01/01/2011', so one year exceeded, then it should give no-0f-days from '01/01/2012'
For 002, date-of-birth is '05/01/2012, so it is not exceeded one years, then it should give no-of-days from '05/01/2012'
For 003, date-of-birth is '15/05/2009', so it is exceeded more than a years, then it should calculate from 15/05/2011 to current date
任何一個可以提供一些思路或查詢幫助