I’m trying to group records by hours with consideration of duration. Assume there are long running processes and there is log data when process has been started and finished. I’m trying to get report by hours how many processes were running The data looks like this Process_name Start End ‘A’ ‘2019/01/01 14:10’ ‘2019/01/01/ 14:55’ ‘B’ ‘2019/01/01 14:20’ ‘2019/01/01/ 16:30’ ‘C’
Tag: sql-server-2008
Already inserted data replace into another UserId
In my Business unit table FK is the UserId ex: UserId =001, BusinessUnit = Bangalore ex: UserId =001, BusinessUnit = Hyd …. Now, I need UserId = 002 is different I want to create same data into 002 The INSERT statement conflicted with the FOREIGN KEY constraint “FK_UserAccess_UserDetails”. The conflict occurred in database “DataBase Name”, table “dbo.UserDetails”, column ‘UserId’. Answer
How to add next and subtract preceding row in SQL Server based on condition
I am trying to calculate the cumulative sum based on TranslationType column in SQL Server. Sample data: Id TransactionType Value ————————- 1 Receipt 10 2 Issue …
Sort by Name first then number in sql query from a delimited string
We have designed to register customer’s station-division records in 1 field. So the table rows looks like this. create table test4 (f2 varchar(100)) insert into test4 (f2) values (‘A08-0100’) insert …
SQL Format(‘MMMM’) does not work in SQL Server 2008
I had this query select format([time], ‘MMMM’) as ‘Month’, count([time]) as ‘Application Usage’, count([time]) as ‘Application Usage’ from UserLogs UL where [time] >= …
Stored Procedure Data Type Conversion Error
I try to execute the following SP it gives me this following error. Msg 8114, Level 16, State 5, Procedure TEST, Line 55 [Batch Start Line 12] Error converting data type nvarchar to …
How to set succeeding row values as empty if same with previous row
How can I convert this table: +———————+——————————-+——-+——-+ | PropertyName | Emergency | Count | Total | +———————+—…
SQL subquery with latest record
I’ve read just about every question on here that I can find that is referencing getting the latest record from a subquery, but I just can’t work out how to make it work in my situation. I’m creating …
sum columns of a table, grouping by table partition
I have a table which holds daily metrics : |DateID | Metric1 | Metric2| 20190501 24 34 20190502 25 56 ….. …. …. The table has more than 150 million rows. …
Selecting Max Value, However Prioritising Certain Values
I have three tables that are joined. TableA has unique values for Column1 (ID) which joins on TableC on Column1 which has non-unique values. I’m currently joining these based off the max value for …