I’m working in SQL Server 2014, and I have the following simple data, which tracks calling history of users: I need to group the ACTIVITY values into one field, which effortlessly be done using the STUFF FOR XML function: However I need to conditionally group these, on the condition that there was more than a 90 day between the activity
Tag: tsql
Assign group_id to all linked records in many-to-many table
There are 3 tables in my DB; Table 1 has ‘Collateral’, Table 2 has ‘Loans’, Table 3 is a multi-link table between 1 and 2; let’s call it ‘Loan_Collateral_link’. A collateral can belong to 1 or more Loans, and a Loan can have multiple Collaterals. What I want to achieve, is create a separate result set (or table) in which
Creating a Data Dictionary with example data (SQL)
I am looking to run a script on a SQL database to create a Data Dictionary with an example of the data for each field. To keep it simple I would just like to include the data from the first row of each table along with each table name and column name So something like this: Table Name Field Name
How to check consecutive values in rows in TSQL?
I have the following table: And I am looking for an output like this with a consecutive available two slots. Preferably the consecutive number should be a variable like @n = 2. How to achieve this in TSQL? Thanks! Update 8/3/2022: I undeleted this question as it is not fair to @lptr, as he/she has the correct solution, but didn’t
T-SQL Calculating Time Quarters
I would like to parse this record across quarter buckets and the length spent in each quarter bucket. Answer Just another option … BRUTE FORCE Example or dbFiddle Results
TSQL – New column value based on other columns with highest level of match
So I’ve got a mapping table with the following information: And another fact table with the following info: Ideally I should add CCode in the fact table with the highest matching value of Number (first) & FCODE (second) So for example the first record: Number: 0123456789 FCode: 12345 should result to have value CCode 6 to be added in the
Sybase select value from XML field
I have a table named data_values stored in SYBASE in the following format: The value field has the following XML format: I want to select from the value field values like value1, value2, etc. but I can’t find a correct query to do this. I have tried: also value is a reserved keyword I think and I need to escape
TSQL “where … group by …” issue that needs solution like “having …”
I have 3 sub-tables of different formats joined together with unions if this affects anything into full-table. There I have columns “location”, “amount” and “time”. Then to keep generality for my later needs I union full-table with location-table that has all possible “location” values and other fields are null into master-table. I query master-table, However some “location” values are dropped
Get different results with the same query in T-SQL and LINQ (EF Core)
I’m trying to retrieve records from a database in Azure and for the checks I run T-SQL queries directly and then pass them to LINQ against the EF Core context, but I’m running into this problem. When I filter for the records with FechaOrientativa greater than or equal to Today, the Estudiar field is equal to ‘pt’, I get 2,296
Capturing difference between 2 tables in one table
I understand my mistake with creating questions in StackOverflow, so I want to rewrite my question. I have two tables. One of them is my target table with old data and the source table with new data. Implicitly I want to compare these 2 tables and get information on which columns have been changed and changed status. So I created