sql server - two query results in datetime compare in sql -
i have 2 sql queries.
select date_first_table first_table and
select date_second_table second_table the above 2 queries may return single or multiple records. need check second query results if date value greater of date value of first query results evaluate true.
i need suggestion on this.
thanks.
is want?
select 'true' second_table date_second_table > (select max(date_first_table) first_table) the statement: "i need check second query results if date value greater of date value of first query results evaluate true." bit hard follow logic. above returns 'true' when values of second query greater values of first query.
the answer may be:
select max('true') second_table date_second_table > (select min(date_first_table) first_table) a key addition max() function, turns aggregation function returns 1 row.
edit:
your question ambiguous in "false" case. 1 answer, suggest in comments is:
select (case when count(*) > 0 1 else 0 end) second_table date_second_table > (select min(date_first_table) first_table); a similar approach use explicit join. although perform less well, may better capture logic:
select (case when count(*) > 0 1 else 0 end) first_table t1 join second_table t2 on t1.date_first_table > t2.date_second_table;
Comments
Post a Comment