Skip to content

Tag: sql-server

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

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&#8217…

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…