Dino’s Journal 📖

SQL

Recently had need of a script that can tell me the time difference in seconds, between two DateTime values in SQL Server. Here is what worked for me:

SELECT DATEDIFF(S, StartDateTime, EndDateTime) AS DurationInSeconds;

Note the first parameter, S, tells the DATEDIFF function to return the difference in Seconds. You can pass in other values as well, like MS for milliseconds or HH for hours.

You can find out more about the DATEDIFF function here.

#SQL #SoftwareDevelopment

For questions, comments and concerns, you can leave me a comment below. You can also find more ways to contact me on this page.

If you're trying to publish a SQL Server database project using Visual Studio, but you're not seeing the Publish dialog box show up, check your other Desktop in Windows. I've noticed that every once in a while, the Publish dialog box shows up in another virtual desktop, instead of showing up on the one you're currently working on.

#SQL #VisualStudio #SoftwareDevelopment


Links to this page: Weeknotes – 012

For questions, comments and concerns, you can leave me a comment below. You can also find more ways to contact me on this page.

Recently had need of a SQL Server script that can tell me if there are open transactions on the database. The script below worked for me:

USE MASTER
GO
SELECT spid,
       PROGRAM_NAME,
       nt_userName,
       loginame,
       DB_NAME(s.dbid) AS DatabaseName,
       CR.TEXT AS Query
FROM   sysprocesses s
       CROSS apply sys.Dm_exec_sql_text(sql_handle) CR
WHERE  open_tran = 1

Source: Welcome To TechBrothersIT: DBA – How To Find Open Transactions In SQL Server

#Database #SQL #SoftwareDevelopment


Links to this page: Weeknotes – 009

For questions, comments and concerns, you can leave me a comment below. You can also find more ways to contact me on this page.