怎样根据传入的变量设置where 语句后的查询条件
例如:表customer 和saleInfo
customer 字段:id,name...
saleInfo 字段:id,F_CustomerID...
存储过程参数:customerID
如果customerID>0,where 后添加条件customer.id=saleInfo.F_customerID
例如:表customer 和saleInfo
customer 字段:id,name...
saleInfo 字段:id,F_CustomerID...
存储过程参数:customerID
如果customerID>0,where 后添加条件customer.id=saleInfo.F_customerID
@strsql=select * from table where .....And customer.id=saleInfo.F_customerID
else
@strsql=select * from table where .....????
If (customerID>0 )
@sqlstr=@sqlstr+ 'where customer.id=saleInfo.F_customerID'.......
拼接个SQL
else
拼接另外一个SQLexex(你拼接的SQL)
@customerID <= 0 or [id] in( select F_CustomerID from saleInfo )
select xx from xx where customer.id = (case when customer.id > 0 then saleInfo.F_customerID else when customer.id end)
where customer.id = (case when customer.id > 0 then saleInfo.F_customerID
else customer.id end)