34,590
社区成员
发帖
与我相关
我的任务
分享
CREATE FUNCTION [dbo].[GetSales]
(
-- Add the parameters for the function here
@Year char(4)
)
RETURNS @t TABLE(product varchar(32), qty varchar(32), value varchar(32))
AS
begin
if @Year='2006'
insert @t select product,qty,value from sales_2006
else
insert @t select product,qty,value from sales_2007
return
end
go
CREATE FUNCTION [dbo].[GetSales]
(
-- Add the parameters for the function here
@Year char(4)
)
RETURNS @t TABLE(product varchar(32), qty varchar(32), value varchar(32))
AS
begin
if @Year='2006'
insert @t select product,qty,value from sales_2006
else
insert @t select product,qty,value from sales_2006
return
end
go
--存儲過程不是更簡單
create proc [GetSales]
@Year varchar(10)
as
exec('select product,qty,value from sales_' + @Year )