How to convert “3 Days 18 Hours 39 Minutes” into seconds in SQL Server?
Tag: sql-server
Select dummy values if where clause returns zero rows
I am using SQL Server 2016. I have a SQL and it has where clause which returns zero or non-zero rows depending on data present in the table at a specific time. For example the SQL is: select step_id, …
Scale CASE WHEN to retrieve non-holiday dates
I have table containing records with start and end dates, so I have to grab every record that started on a Friday, and if any Friday is a holiday, get Thursday, and if Friday and Thursday are holidays,…
Select carried over reports
How do I get the carried over reports + the very first report from the following table? Result should be : 304, 306, 309, and 312. CREATE TABLE [dbo].[test]( [reportID] [int] NOT NULL, [caseID] [int]…
Avoiding duplicates using stuff function and for xml path
I’m having a problem with duplicates using mysql server with stuff function. The database contains few million records and using distinct is out of question (it seems that the query does not even process). This is my database structure: I have been using following structure for this query. The query wor…
Copy data from one row to another in SQL Server in the same table
I have a table that has two variations of data: Table MYDATA I would like to update Version A’s StreetNumber into Version B. There will be thousands of records and the match will be on the Address column I thought to use: But it seems the nesting is not looking at the row to be updated…rather its …
tSQLt apply NOT NULL constraint
How do I apply the NOT NULL constraint back onto a column of a table in tSQLt? CREATE OR ALTER PROCEDURE [test abc].[test abc1] AS BEGIN — Arrange EXEC tSQLt.FakeTable ‘dbo’, ‘table1’; –…
Using ISNULL or COALESCE on date column
I’ve got a date column where some rows have got NULL values. I would like to use ISNULL or something like that to substitute those values with something like ‘N/A’, however, when I try to use ISNULL, I get an error due to two different data types. If I try to convert my Date column to VARCHAR in order to…
How to aggregate values in rows based on condition and getting output in sql?
My table contains few rows, which has to be aggregated. eg: Columns are sites, fuel, sales, date when date ,sites and fuel is same I need to aggregate the sales column for those rows and have one row….
SQL : calculate multiple rows to result
How to get result table by calculate multirow? Name Type Value —————————— Name1 Plus 5000 Name1 Minus 1000 Name2 Plus 3000 Name2 Minus 2000 …