简体   繁体   中英

Convert SQL Server Query to MS Access

Here is my SQL Server Query that needs to be converted to MS Access -

declare @StartDateTime datetime, @EndDateTime datetime
set @StartDateTime  = '8/17/2013 19:00:00'
set @EndDateTime = '8/18/2013 23:00:00'

WHILE @StartDateTime <> @EndDateTime
Begin
  SELECT TOP 1 tablename.Field2, tablename.Field3
  FROM tablename
  WHERE tablename.SampleDate >= DateAdd(mi,0,@StartDateTime) And tablename.SampleDate <= DateAdd(mi,9,@StartDateTime)    
  SET @StartDateTime = DateAdd(mi,10,@StartDateTime)
  if @StartDateTime = @EndDateTime
   Break;       
END

I appreciate any help. Thanks

That T-SQL script has no direct equivalent in Access. It returns multiple result sets, one for each 10-minute interval between @StartDateTime and @EndDateTime, each containing a single (apparently random) sample from that interval. Access queries only produce one result set (recordset).

If you update your question to explain what you actually want to do with those multiple result sets then we might be able to help you more, but for now the answer to

How can I convert this SQL Server query to an Access query?

is:

You can't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM