how to check data with in range in fdate and tdate in sql server

  • Hi friends i have small doubt in sql server here i want data based on condition same id and status is equal to s then that date value be how to write query in sql server

    Table :emp

    id |status |date(mm-dd-yy) |fdate(mm-dd-yy) |tdate(mm-dd-yy)

    1 | S |03-16-11 | |

    1 | b | | 03-15-11 |03-18-11

    1 | s |03-17-11 | |

    1 | b | | 04-20-12 |04-30-12

    1 | S |04-20-12 | |

    1 | s |04-10-12 | |

    1 | s |10-01-14 | |

    1 | b | |10-02-14 |10-25-14

    2 | s |01-18-12 | |

    2 | b | |01-18-12 |01-28-12

    2 | b | |03-10-13 |03-24-13

    2 | s |03-16-13 | |

    2 | s |03-10-13 | |

    2 | s |03-23-13 | |

    2 | b | |04-20-13 |04-27-13

    2 | s |07-01-14 | |

    the table (status = s, id, date) compare it with status = b, same id number and date ( Date value from status s) with the date range of fdate and tdate . if that data with in range then Billing yes other wise billing no

    output like

    id |status |date(mm-dd-yy) |fdate(mm-dd-yy) |tdate(mm-dd-yy) |Billing

    1 | S |03-16-11 | | |yes

    1 | s |03-17-11 | | |yes

    1 | S |04-20-12 | | |yes

    1 | s |04-10-12 | | |no

    1 | s |10-01-14 | | |no

    2 | s |01-18-12 | | |yes

    2 | s |03-16-13 | | |yes

    2 | s |03-10-13 | | |yes

    2 | s |03-23-13 | | |yes

    2 | s |07-01-14 | | |no

    i tried query like below

    select * from ( select * from emp a where status ='s')a

    inner join

    (select * from emp b where status='b')b

    on a.pn=b.pn

    where a.date<=b.date1 and a.date>=b.date2. || its not give exactely result. please tell me how to write query in sql server

  • Duplicate post, answer to this one please.

    😎

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply