Relative Content

Tag Archive for sqlt-sql

is there any possible simplification of the SQL PIVOT operator?

The pivot operator is a common requirement for querying data, but requires a cumbersome syntax that I always have to look up and usually find it easier just to copy from SSMS and paste into Excel to get a quick answer, so I have never bothered to memorize the syntax. I’m not new to this; I have worked around this for decades, but wanted to ask community if there was something I missed…

Trying to delete 2 id table using union

I am trying to perform a delete on a table that has 2 id’s with the differences of a view that I am using 2 ids on as well. Here is how I am finding the differences in Id’s:
Union of differences. Let’s say I have one table named Worker with columns WorkerId and ShiftId
Table1 data:

I am trying to insert randomly generated numbers into an empty table using a cursor

I am trying to insert randomly generated numbers into an empty table using a cursor but I want it to go through all possible combinations with out having duplicates of the same number and I want to add conditions to what needs to be inserted. I want it to run through the code multiple times, I don’t want to have to execute it to the whole time to get like 1 million rows.

Calculate days in between status change

I’m not sure how to code to get the result I’m looking for. I hope the community can point me in the right direction. I need to run a report against the Rent History table, and I expect the report to look like the Final Result. Please see the image for details.

There are three tags in the Rent History table. I was able to use ROW_NUMBER() OVER (PARTITION BY) to determine the On/Off Rent start date based on the position. This is where I stopped because I’m not sure what to do next. So far, this is the code that I have.