I would like to update the records from one table to another table and if there are new records then insert those records. In this case, the new records are having the same ID but different column attributes. When I am running the update and insert query, it’s only considering the last entry from table …
Tag: sql-server
Recursive select that selects rows based own plus childrens values
I need to select rows in a table like this: Select all rows in the table where both conditions are met: Condition 1: the value column should not match with any value in table v Condition 2: no decendent (on any level, ie: child or sub child, sub- sub- child etc) has a value that matches with any value in
Flag “yes/No” if the subsequent row has same ID
I have data like this. If the same id is present in the next row, I want to flag as Yes. If it is not present then Make it as ‘No’. Can you kindly help me with the query? Thanks Answer The problem with multiple rows for the same ID and no other column that can be used to futher
Turn Cross Apply opensjson results into columns
We have a table that has a field with some json. using cross apply I was able to turn those pairs into columns: So how do I turn this into something like : Thanks. Answer If you know the limited set of possible key names in advance, you can just use PIVOT: But you can’t write a PIVOT if you
Second member of Azure AD group can not create schema in Azure SQL database
We have a curious issue with our Azure SQL database with AAD authentication. We have created a role (dbt_user) with all permissions, and excluded some schemas: Then, we add an AAD group (myAADGroup) as user, and add this to the role above: There are 2 members of the AAD group: user1@domain.com and user2@domai…
How to perform Case statement inside a select statement?
I wanted to put ‘No record’ on the column instead of NULL if the datediff function returns a null value. So far this code only throws Incorrect syntax near ‘CAST’, expected ‘AS’. but I don’t know what data type should I put in the CAST parameter , since if there’…
Why is SQL Server Full Text Search indexing SCR or SUR acronym followed by a number, together?
I discovered a very odd behavior of SQL Server Full Text Search which is indexing SUR, SCR and possibly some other acronyms, together with a number following it – as “Exact Match”. keyword group_id phrase_id occurrence special_term display_term expansion_type source_term s u r 1 2 3 4 5 1 0 …
Finding Occurrence of the duplicate values
I have table with 3 columns (id, Name, Occurrence), I want to update the Occurrence column ,based on the id column, attached snap for the reference. for example if my id column has “606” value 3 times then my occurrent column should have 3 against all the “606” value. Below is the meth…
How to get 1st and 3rd Saturday and all Sunday between 2 dates using sql
Given a date range, I’d like to return all of the Saturdays and Sundays that fall within that range, with these conditions: Include Saturdays only if their ordinal position is either the 1st or 3rd Saturday within the month they fall (not within the entire range). Include all Sundays, along with the ord…
How do I add a column that counts unique instances of another columns data
I am an end user that does not work with SQL everyday. However I am sometimes asked to add modify existing queries to provide new data. Currently I have a query that calculates (counts) the occurrences of a column labeled (Qid) and displays the top 5 based on count. It was necessary to use a select statement …