sql - Compare the date from other table -


using sql sever 2005

table1

id startdate enddate  001 02/23/2010 07/22/2010 002 05/03/2010 null 003 02/02/2011 null ... 

table2

date

02/24/2011 02/25/2011 ... ... 

condition

  • if enddate not null startdate compare max(date) table2, if startdate > 6 month should display "expired"

how make query above condition.

need query help.

select    startdate,   [status]=case           when datediff(m,startdate,(select max(date) table2))>6         'expired'          else 'valid'         end    table1   enddate not null 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -