现在有三个表 a,currentb,historyc其中表a中有字段id,name,otherid,//id为主键自增
    表currentb中有字段otherid,currentdate,names //otherid为主键自增,currentdate为时间
    表historyc中有字段historycid,otherid,startdate,enddate,names //historycid为主键自增,startdate,enddate为时间我想求出在存储过程中有一个输入参数dates(时间),然后根据这个时间,先在currentb表中判断,如果dates大于或等于currentb中的currentdate,则取currentb中的这条记录,然后与表a进行连接,通过otherid.如果dates小于currentb中的currentdate,则取historyc中的记录(historyc中有多条记录的otherid是相同的),取historyc中记录的条件是dates>=startdate and dates<enddate,然后把取出来的记录与表a进行连接,也是通过otherid。最后显示所有取出来的数据。求各位大哥大姐帮忙