If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

What I need to do is create another column that utilizes the DATEDIFF function to find the time between lastruntime. I know I can use DATEDIFF, but the problem lies with the fact that this table (jobs) has no unique column.

i can use the following query, but it requires me to manually enter in the start and end dates...

True, and I could have done a CTE dance too, but there were some quirks with CTEs in a few of the SQL 2008 service packs. I went with what Lewis Grizzard said: "Shoot low boys, they're riding Shetland Ponies" and provided SQL that ought to work with any SQL that supports SQL-92.

-PatP

In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Just an observation, but this code gets a wee bit wonky when there are "ties" in the lastruntime column. Depending on how you (and your application) think about your data, you might need to revisit that issue.

-PatP

In theory, theory and practice are identical. In practice, theory and practice are unrelated.