{"id":294,"date":"2025-09-05T01:07:15","date_gmt":"2025-09-05T01:07:15","guid":{"rendered":"https:\/\/supportingelement.com\/?p=294"},"modified":"2025-09-05T01:07:15","modified_gmt":"2025-09-05T01:07:15","slug":"identifying-field-changes-using-the-lag-function","status":"publish","type":"post","link":"https:\/\/supportingelement.com\/index.php\/2025\/09\/05\/identifying-field-changes-using-the-lag-function\/","title":{"rendered":"Identifying Field Changes using the &#8220;LAG&#8221; Function"},"content":{"rendered":"\n<p>There are a number of scenarios where it is necessary to identify changes in specific fields in Effective Dated data sets.  For example: identifying changes to Full\/Part Time Status in Job Data.<\/p>\n\n\n\n<p>The following screenshot shows the results of a PS Query that uses the Oracle SQL &#8220;LAG&#8221; function to identify changes to the FULL_PART_TIME field in Job Data.  The Full\/Part Time Status for the selected employee was changed from &#8220;P&#8221; to &#8220;F&#8221; on 19th Jul 2025.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"254\" src=\"https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/QueryResults-1024x254.png\" alt=\"\" class=\"wp-image-295\" srcset=\"https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/QueryResults-1024x254.png 1024w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/QueryResults-300x74.png 300w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/QueryResults-768x190.png 768w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/QueryResults-660x164.png 660w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/QueryResults.png 1149w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>The Oracle SQL &#8220;Lag&#8221; function is used to create the &#8220;Prev Full\/Part&#8221; field shown above.  This function retrieves the field value from the previous row in the data set, as follows:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"497\" height=\"420\" src=\"https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/LagExpression.png\" alt=\"\" class=\"wp-image-296\" srcset=\"https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/LagExpression.png 497w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/LagExpression-300x254.png 300w\" sizes=\"auto, (max-width: 497px) 100vw, 497px\" \/><\/figure>\n<\/div>\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><code>LAG(A.FULL_PART_TIME, 1, 0) <br>OVER (ORDER BY <\/code><br><code>A.EMPLID, <\/code><br><code>A.EMPL_RCD, <br>A.EFFDT, <br>A.EFFSEQ)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The &#8220;Expression&#8221; can then be used a a field in the PS Query, as shown below:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"426\" src=\"https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/ChangeFullPartQuery-1024x426.png\" alt=\"\" class=\"wp-image-297\" srcset=\"https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/ChangeFullPartQuery-1024x426.png 1024w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/ChangeFullPartQuery-300x125.png 300w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/ChangeFullPartQuery-768x319.png 768w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/ChangeFullPartQuery-660x275.png 660w, https:\/\/supportingelement.com\/wp-content\/uploads\/2025\/09\/ChangeFullPartQuery.png 1529w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>Microsoft SQL Server also has a &#8220;LAG&#8221; function, but with slightly different syntax.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a number of scenarios where it is necessary to identify changes in specific fields in Effective Dated data sets. For example: identifying changes to Full\/Part Time Status in Job Data. The following screenshot shows the results of a PS Query that uses the Oracle SQL &#8220;LAG&#8221; function to identify changes to the FULL_PART_TIME\u2026 <span class=\"read-more\"><a href=\"https:\/\/supportingelement.com\/index.php\/2025\/09\/05\/identifying-field-changes-using-the-lag-function\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":1,"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/posts\/294\/revisions\/298"}],"wp:attachment":[{"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportingelement.com\/index.php\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}