I have a pre-processed table which I want to group every pair into one record containing data from fields of both records. |——————-|—–|—-| |Timestamp |Event|User| |———-…
Tag: tsql
Pivot One Column and Retain SUM,AVG,COUNT Columns
Let’s say I have a table PRODUCT like this. ProductName Amount ——————— Soap 1.10 Toothbrush 2.00 Towel 3.00 Soap 3.00 Then I get their sum, average …
How to use scalar variable in XML Path query SQL?
I want to pass table name into into a scalar variable @Table_Name as a string. But I am getting error as: Must declare the table variable @Table_Name. How to achieve the same? Below is my code snippet: Answer So I created a temporary table using the input provided by the user and used that temp table in the query. Following
How to group by row in diferents columns
I have this table in SQL, I need to group it by the report name and I need to split the price_bucket column and the count_sales column in diferents rows. I think that I should use the PIVOT funtion in SQL Server and an intermediate table. How should I do it? This is what the final table should look like:
Eliminate the rows that becomes same after swapping as in original table in SQL Server
I have a table which contains data as follows: I want a table which do not have Mumbai—>Jaipur as it is present already before being swapped. Similarly, Lucknow—>Indore is not required. All other entries must come as it is which is there in the existing table. Can any body help. Note: Table must not have any id or S.No. in
SQL – Finding foreign key ID associated with a combination of multiple/variable table variable rows
In a Microsoft SQL Server stored procedure, I have table variable, @PlayerComboStrategy, with a variable number of rows, and columns PLAYER_ID, POSITION_CODE, STATUS_CODE. I am looking for the most …
SQL Query to get the compliance status
I’m trying to get the following query constructed I got a table called client_vendor as follows. This stores the details of answers provided by client against a vendor for 4 questions. client_vendor …
Building an Employee Date Matrix
I have a list of employees, along with list of cities they’ve worked in. I need to build a matrix (in SQL Server) of start/end dates by city to determine where they were at any given period in time. The “end date” would be exactly the date before they appeared at a new location. I’ve included an example of the
SQL: Delete XML node in an UPDATE statement
I keep getting this error: In search of a solution to this answer I came across this SO article about updating in a SELECT statement: How do I UPDATE from a SELECT in SQL Server? Example… Note: the field CustomProperties is nvarchar(max) which I convert to xml. I also tried a cursor (nasty things), but getting the same error. Is
I need a query that selects individuals with a birth date from January 1 two years ago through yesterday’s date
I need a query that will pull all children with a birth date from two years ago through yesterday. So using today as a for instance the query would return everyone with BirthDT from 1/1/2018 to 3/4/2020. For the remainder of 2020 the Start Date will always be 1/1/2018 and End Date will vary depending on the date the query