Share via

identify what has changed

arkiboys 9,711 Reputation points
2023-07-26T12:04:56.81+00:00

hello,

I have a dataset which contains data for different year, month, day columns

I would like to get the changed data since one date to another

example of data:

company		code		state		planned		moisture	year		month		day
--------------------------------------------------------------------------------------------------------------------
94925		code1		complete	22.9		11.999		2023		05		20
94925		code1		complete	22.9		12			2023		05		21
94925		code1		complete	22.9		12			2023		05		22
94925		code1		delete		22.9		12			2023		05		23
...
87654		code2		complete	18			7			2023		05		20
87654		code2		complete	18			9			2023		05		21
87654		code2		planned		18			9			2023		05		22
87654		code2		planned		18			9			2023		05		23

...

The unique columns are company and code

There are thousands of rows which are captured into each year, month and day as you see above...

I would like to find-out which rows have changed (Including what has changed) say from 2023-05-20 to 2023-05-25

Hope you see what I mean.

Thank you

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


1 answer

Sort by: Most helpful
  1. Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
    2023-07-26T21:13:52.52+00:00

    The unique columns are company and code

    Are they? Why then are there multiple rows per (company, code)?

    Your question is not clear, but if you want compose a date from the three columns year, month and day, you can use the function datefromparts. For instance:

    SELECT datefromparts(2022, 11, 26)
    

    returns 2022-11-26.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.