34,588
社区成员
发帖
与我相关
我的任务
分享
declare @endtime datetime
declare @begintime datetime
declare @year nvarchar(4)
declare @ln nvarchar(1000)
declare @str nvarchar(1000)
select @endtime=getdate()
,@begintime=dateadd(dd,-120,getdate())
,@year=year(getdate())
--统计目标表中LN站特定时间的记录总数
declare @select2 int
--统计LN表中特定时间的记录总数
set @str='SELECT count(*)
FROM openrowset(''SQLOLEDB'',''172.19.18.133'';''sa'';''sa'',Meso_'+@year+'.dbo.LN_'+@year+' )
where DATEPART(minute, cast(观测时间 as dateTime))=0 and' + @begintime +' <观测时间 and 观测时间' < @endtime
exec(@str)
观测时间是什么格式,最好是这种格式:'年-月-日'
--赋值当前时间
declare @endtime datetime
declare @begintime datetime
declare @year nvarchar(4)
declare @ln nvarchar(1000)
declare @str nvarchar(1000)
select @endtime=getdate()
,@begintime=dateadd(dd,-120,getdate())
,@year=year(getdate())
--统计目标表中LN站特定时间的记录总数
declare @select2 int
--统计LN表中特定时间的记录总数
set @str='SELECT count(*)
FROM openrowset(''SQLOLEDB'',''172.19.18.133'';''sa'';''sa'',Meso_'+@year+'.dbo.LN_'+@year+' )
where DATEPART(minute, cast(观测时间 as dateTime))=0 and '+cast(@begintime as nvarchar)+' <观测时间 and 观测时间 <'+cast(@endtime as nvarchar)
exec(@str)
--TRY
--TRY
--赋值当前时间
declare @endtime datetime
declare @begintime datetime
declare @year nvarchar(4)
declare @ln nvarchar(1000)
declare @str nvarchar(1000)
select @endtime=convert(varchar(10),getdate(),120)
,@begintime=convert(varchar(10),dateadd(dd,-120,getdate()),120)
,@year=ltrim(year(getdate()))
--统计目标表中LN站特定时间的记录总数
declare @select2 int
--统计LN表中特定时间的记录总数
set @str='SELECT count(*)
FROM openrowset(''SQLOLEDB'',''172.19.18.133'';''sa'';''sa'',Meso_'+@year+'.dbo.LN_'+@year+' )
where DATEPART(minute, cast(观测时间 as dateTime))=0 and '+@begintime+' <观测时间 and 观测时间 <'+@endtime
exec(@str)
--TRY
--赋值当前时间
declare @endtime datetime
declare @begintime datetime
declare @year nvarchar(4)
declare @ln nvarchar(1000)
declare @str nvarchar(1000)
select @endtime=getdate()
,@begintime=dateadd(dd,-120,getdate())
,@year=year(getdate())
--统计目标表中LN站特定时间的记录总数
declare @select2 int
--统计LN表中特定时间的记录总数
set @str='SELECT count(*)
FROM openrowset(''SQLOLEDB'',''172.19.18.133'';''sa'';''sa'',Meso_'+@year+'.dbo.LN_'+@year+' )
where DATEPART(minute, cast(观测时间 as dateTime))=0 and '+@begintime+' <观测时间 and 观测时间 <'+@endtime
exec(@str)