Search
 
SCRIPT & CODE EXAMPLE
 

SQL

how to get the date diff on once field in sql server

SELECT t1.OrderNo,DATEDIFF(day,t1.LoadedStartDate,t2.LoadedStartDate)
FROM UnnamedTableFromQuestion t1
       INNER JOIN
     UnnamedTableFromQuestion t2
       on
         t1.OrderNo = t2.OrderNo
WHERE t1.OpNo = 1 and
      t2.OpNo = 4
      
////////////////////////////////////////////////////////////////

select cur.unique_id_field, cur.seq_no, cur.date_created ,

  datediff(second, prv.date_created, cur.date_created) as diff_in_seconds

from yourtable as cur

  join yourtable as prv

    on cur.seq_no = prv.seq_no + 1;
Comment

how to get the date diff of 2 dates in the same fieldin sql server

WITH Partitioned AS(	SELECT *, ROW_NUMBER() OVER (PARTITION BY cu_id, date ORDER BY cu_id, date) AS RowNumber	FROM @Table) SELECT 	*,	CASE 		WHEN RowNumber > 1 THEN 0		ELSE COALESCE(DATEDIFF(DAY, (SELECT MAX(date) FROM @Table WHERE date < a.date AND cu_id = a.cu_id), a.date), 0)	END AS Days_betweenFROM Partitioned a
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql multiple order by 
Sql :: select * where id = 1,2,3 
Sql :: SQL Modify Column in a Table -PostgreSQL 
Sql :: reindexing all tables sql server 
Sql :: rename a column in sql server 
Sql :: sql server phone constraint 
Sql :: how to change column name in mysql 
Sql :: select top 3 sql 
Sql :: mysql identified by syntax error 
Sql :: create tablespace oracle multiple datafiles 
Sql :: calculate percentage in sql 
Sql :: mysql drop key 
Sql :: postgresql float 2 decimal places 
Sql :: setting default value for Boolean data type in SQL 
Sql :: how to view created temporary tables in mysql 
Sql :: list table columns sql 
Sql :: sqlalchemy empty table 
Sql :: sql delimiter to columns 
Sql :: postgres trigger insert into another table 
Sql :: creating table in mysql 
Sql :: mysql create user with grant privileges 
Sql :: full join sql 
Sql :: how to get connect string from mysql database 
Sql :: grant all privileges database postgres to user 
Sql :: postgres how to add field created at 
Sql :: power query add row 
Sql :: mysql run script 
Sql :: insert or ignore postgres 
Sql :: postgresql newline character 
Sql :: mysql not starting in xampp 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =