I’ve seen a very few questions like this one but none have a solution that quite works with with the structure I have.
My current query creates a table with 4 columns, 2 of which are dates.
I declare this as a table @tblTransactions which I later call in a select statement.
I need the final select statement to have a 5th column which shows the number of days between the two dates.
SELECT *
,(t.PremDueDate - t.LastTdate) AS 'tpFactor' <-------- This doesn't work
FROM
@tblTransactions t
the above code obviously doesn’t work since PremDueDate and LastTdate are both of datatype date.
Using SQL Server Management Studio 2010
Use
DATEDIFF()to get the number of days between two dates: