Link to home
Start Free TrialLog in
Avatar of janhoedt
janhoedt

asked on

SQL query: date diff as new column?

Hi,

Please see https://www.experts-exchange.com/questions/29173210/SSRS-sort-on-datediff.html

Is there also a way to do a plain sql query (not ssrs)which puts the date diff in a separate (new) column and shows it it days,hours,minutes?

J
Avatar of Arana (G.P.)
Arana (G.P.)

you can use computed columns when creating the table
CREATE TABLE dbo.Products
   (
      ProductID int IDENTITY (1,1) NOT NULL
,DateReleased 
,DateCreated
,(DateDiff("d",Fields!DateReleased.Value, Fields!DateCreated.Value))
    )
;

Open in new window


or use them during a query

select field1,field2,DateDiff("d",Fields!DateReleased.Value, Fields!DateCreated.Value) as Mydatediff

Open in new window

Avatar of janhoedt

ASKER

Sorry, table us already existing and cannot recreate it due to foreign key
ASKER CERTIFIED SOLUTION
Avatar of Arana (G.P.)
Arana (G.P.)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial