I have the following table DBName Server Status UpdateTime DB1 server1 NULL 5/4/2019 DB1 server1 NULL NULL DB2 server2 NULL 6/4/2019 DB2 server2 NULL 6/4/2019 DB3 server2 NULL NULL …
Tag: tsql
Join repeatedly until a string is present?
While querying a subset of our employees, I’m trying to add a field for the SVP they “roll up” to. Employees may have anywhere from 1 to 5 or 6 degrees of separation from their SVP. The trouble is, …
XML load is slow. Using text() when reading XML file with attribute-centric mapping
I am reading in an XML file into the database. It works fine however it is very slow. I was wondering if I can use text() in order to speed the process up similarly to the solution in this post: Xml …
Filter rows over partitions
Suppose I have the following table: +——-+————+ | nGroup | Status | +——-+————+ | 1 | DONE | | 1 | UNKNOWN | | 1 | DONE | …
Getting count depending on subquery
In my SELECT statement below, I’m looking to get a COUNT of connections from a table, where connections are defined as 1 connection per unique transactionID. Thus, in my COUNT, I want to check to make …
Using CASE WHEN to assign buckets
Fairly new to coding. I’ve created a new column that outputs the days a task is overdue using DateDiff. I then want to take the result of the DateDiff and assign it an expression (>60 days overdue, 30-…
How to insert new rows based on values in other columns in sql server?
I have a dataset like below: Id A14_Comment A15_Comment A16_Comment 1 Comment1 null null 2 Comment2 Comment3 Comment4 3 null Comment5 …
How to remove rest of the ordered rows with the same ID after the first row which occurs more than once with that ID?
I have the following structure for the table DataTable: every column is of the datatype int, RowID is an identity column and the primary key. LinkID is a foreign key and links to rows of an other …
How to remove rest of the rows with the same ID starting from the first duplicate?
I have the following structure for the table DataTable: every column is of the datatype int, RowID is an identity column and the primary key. LinkID is a foreign key and links to rows of an other …
Count alpha characters in string field in SQL Server
I am using SQL Server Management Studio v17.9.1. I have column in a database table that contains alphanumeric strings. I need to count the letters in the string and produce a table of the aggregate …