CREATE procedure gethisData
@maxdate int,
@mindate int,
@fieldname varchar(30)
as
begin
DECLARE @strsql varchar(300)
select @strsql='select 日期,时间, '+@fieldname+' FROM OPENDATASOURCE(''SQLOLEDB'''+',''Data Source=.;User ID=sa;Password=123'''+'
).shengli.dbo.hisdata where 日期>='+str(@mindate)+
' and 日期<'+str(@maxdate)
exec(@strsql)
end
GO
博客展示了一个SQL存储过程代码,该存储过程名为gethisData,接收最大日期、最小日期和字段名作为参数,通过拼接SQL语句从指定数据源获取历史数据,最后使用GO结束。
488

被折叠的 条评论
为什么被折叠?



