查询条件动态指定,即:select field1,field2,field3 into #temp from testtable where 1=1 +动态传入存储过程判断条件(如: and field1=2)请问怎么解决,我用exec(查询语句变量),然后再用:select * from #temp 但这时 #temp 已经无效了,真是头痛,还请指点一二.
CREATE FUNCTION SalesByStore (@storeid varchar(30))
RETURNS TABLE
AS
if @storeid = ''
RETURN (SELECT title, qty
FROM sales s, titles t
WHERE s.stor_id = @storeid and
t.title_id = s.title_id)
else if ...