SQL语句,一个是时间条件,一个是字段值条件,如何写在同一语句上??

来源:百度知道 编辑:UC知道 时间:2024/05/17 20:55:11
这句话没问题,是显示前一天的记录:
sql="Select A.AccountNo, A.CardNo, B.CustomerName, B.DeptNo, B.OldLeftMoney, B.LeftMoney, B.Je, B.ConsumeTime From tb_inf B Inner Join tb_Customer A On A.AccountNo = B.AccountNo where ConsumeTime between cast(GetDate()-1.5 as int) and GetDate()order by A.CardNo asc"
如何在这句话的基础上加下面一个条件::??
DeptNo like '%001003001001%'
望大家指教

sql="Select A.AccountNo, A.CardNo, B.CustomerName, B.DeptNo, B.OldLeftMoney, B.LeftMoney, B.Je, B.ConsumeTime From tb_inf B Inner Join tb_Customer A On A.AccountNo = B.AccountNo where ConsumeTime between cast(GetDate()-1.5 as int) and B.DeptNo like '%001003001001%' and GetDate()order by A.CardNo asc"

加order by 子句前面即可:
sql="Select A.AccountNo, A.CardNo, B.CustomerName, B.DeptNo, B.OldLeftMoney, B.LeftMoney, B.Je, B.ConsumeTime From tb_inf B Inner Join tb_Customer A On A.AccountNo = B.AccountNo where ConsumeTime between cast(GetDate()-1.5 as int) and GetDate() and DeptNo like '%001003001001%'
order by A.CardNo asc"