我有两张不同的桌子
User_ID Locarion start_date end_date ---------- ------------- ------------- ------------- 1 South 1-1-2018 1-5-2018 2 North 1-2-2018 1-11-2018 1 East 1-5-2018 1-9-2018
User_ID User_name ---------- ------------- 1 Mary 2 Sara
使用if语句检查当前日期是否在星号和结束日期之间,将该位置返回为当前日期
我希望这是结果表
User_ID User_name current_location ---------- ------------- ------------- 1 Mary East 2 Sara undeined
请帮忙
请尝试以下查询:
select user_id,user_name,collasce(location,'undefined')
from usertable u left join locationtable l on u.user_id=l.user_id
and getdate>=startdate and getdate<=enddate