创建一个函数,比如: CREATE FUNCTION test(@finddate varchar(10)) RETURNS table AS RETURN (select * from 表1 where 日期=@finddate) go 调用时: SELECT * FROM dbo.test('2002-10-26')
听sky_blue(老衲) 的,用UDF ,不过只能在SQL 2000下用。 帮助里的例子:CREATE FUNCTION SalesByStore (@storeid varchar(30)) RETURNS TABLE AS RETURN (SELECT title, qty FROM sales s, titles t WHERE s.stor_id = @storeid and t.title_id = s.title_id)使用时用select * from SalesByStore('aaa')就可以了。
CREATE FUNCTION test(@finddate varchar(10))
RETURNS table
AS
RETURN (select * from 表1 where 日期=@finddate)
go
调用时:
SELECT *
FROM dbo.test('2002-10-26')
帮助里的例子:CREATE FUNCTION SalesByStore (@storeid varchar(30))
RETURNS TABLE
AS
RETURN (SELECT title, qty
FROM sales s, titles t
WHERE s.stor_id = @storeid and
t.title_id = s.title_id)使用时用select * from SalesByStore('aaa')就可以了。