I’m currently working on a query where I need to distinct ID based on the latest date created. Here is my diagram | ID | ModelID | LocationId | DateCreated | |——+—————-…
Tag: sql-server-2008
Average across rows in SQL Server 2008
I have the following table Data Data1 Data2 YTD ————————- 1 2 3 2 3 4 3 3 6 In the YTD column I have to average the rows data. I can …
How to get hours between two dates in SQL Server?
I have two dates 2019-01-02 12:33:36.000 and 2019-01-09 19:05:18.000 I want to calculate the hours and mins between the two excluding Saturday and Sunday. I can calculate the difference but not sure …
Simulating NETWORKDAYS returns wrong business days
I created a NETWORKDAYS-like function on sql based on this solution wich returns correctly the business days while the records (BEG and END) are on business days. BEG END businessd —-…
Convert/get varchar variable to YYYYMM
I have 4 CTE’s in this table and the third one contains a DATETIME converted to VARCHAR (with format based on the requirement) as startDate in DD/MM/YYYY format. The last cte does calculations based …
With CTE, compare rows with same ID and updating oldest one to 0 SQL Server 2008
Asked for the logic yesterday, now I’ve worked a way around. I have a big table used for reporting (170k~ rows) and many of them are “duplicated” but with updated dates (e.g. old record says John Doe …
Using Pivot function In SQL Server
I have the below table Code Data SL Payroll 1 GV Payroll 3 Global Payroll 1 TimeHCM 1 SL Payroll 0 GV Payroll 0 Global Payroll 0 TimeHCM 0 SL …
MS SQL Server Update or Clear based on matching values
I need some help in a scenario that I am working on. I have two tables Product_Staging and Product. The contents of the table are below. Product_Staging: Account_No Product_No …
Datagridview update to multiple tables without using bindingsource or tableadapter
I have a working Select query but since it contains multiple tables I can’t update it from my datagridview. I’m sure it can be re-written to allow updates, but my SQL is quite limited. SELECT d….
Get a particular value from String
I want to remove particular value from my string. My string can be of any length. E.g. string 1: {“ABC”:1,”ABC_DT”:-1,”ABC_DBQty”:0,”ABC_DSQty”:0,”ABC_LMT”:1,”ABC_DT”:-1,”CTSD”:”TEST”,”SD”:1,”…