Link to home
Create AccountLog in
Avatar of databoks
databoksFlag for Denmark

asked on

Select TOP 14 highest Datetime.

DECLARE @SETID  BIGINT;

SET @SETID = (SELECT BACKUPSETID FROM DBO.JobStatusDaily WHERE LoginName = @LoginName AND JobName = @JobName);

SELECT TOP 14(DBO.JobHistory.PrevStatus) AS 'Tidligere Status', PreDayName as 'Dag', PrevStartTime as 'Tid'  FROM DBO.JobHistory
order by dbo.JobHistory.PrevStartTime

Open in new window


I want to select the highest datetime and then 14 dates down.
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Your query gives you the 14 most recent start times regardless of setid, jobname and loginname.
The correct query should be

SELECT TOP (14) DBO.JobHistory.PrevStatus AS 'Tidligere Status', PreDayName as 'Dag', PrevStartTime as 'Tid'  FROM DBO.JobHistory
order by dbo.JobHistory.PrevStartTime

But what exactly do you want?
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I Don't know if it isthe case, but as I understand you need only to diorder the date
Just order desc to field which you want and get upper 14 records. You will get your desire result.
Avatar of databoks

ASKER

Thanks for the code. What i need is i selected the TOP 14 newest dates.  The code works. :)