{"id":42,"date":"2008-04-16T16:31:38","date_gmt":"2008-04-16T21:31:38","guid":{"rendered":"http:\/\/www.cfchimp.com\/wordpress\/?p=42"},"modified":"2024-12-05T20:02:09","modified_gmt":"2024-12-06T01:02:09","slug":"prepend-existing-data-in-sql","status":"publish","type":"post","link":"https:\/\/csimmons.dev\/blog\/2008\/04\/prepend-existing-data-in-sql\/","title":{"rendered":"Prepend existing data in SQL"},"content":{"rendered":"<p><strong>Disclaimer:<\/strong> This tip will probably be really basic for most SQL folks.<\/p>\n<p><strong>The task:<\/strong> The company I work for has a web application that does some basic tracking of grants.  The system feeding information to this application just had an across the board change to the numbering scheme of the grants.  All grants must have a prefix of &#8220;999-&#8220;.  Therefore, any grant not beginning with &#8220;999-&#8221; must be updated.  Example: a grant with the current number 8789966 needs to be 999-8789966.<\/p>\n<p><strong>The solution:<\/strong> The SQL below does two things.  It updates all the grants to prepend the 999- prefix while also skipping any grants that are already correctly prefixed.<\/p>\n<p><code><br \/>\nUPDATE tbl_grants<br \/>\nSET grant_no = '999-' + grant_no<br \/>\nWHERE grant_no NOT LIKE '999-%'<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Disclaimer: This tip will probably be really basic for most SQL folks. The task: The company I work for has a web application that does some basic tracking of grants. The system feeding information to this application just had an across the board change to the numbering scheme of the grants. All grants must have &#8230; <a title=\"Prepend existing data in SQL\" class=\"read-more\" href=\"https:\/\/csimmons.dev\/blog\/2008\/04\/prepend-existing-data-in-sql\/\" aria-label=\"Read more about Prepend existing data in SQL\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_cloudinary_featured_overwrite":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[68],"tags":[12,16],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-developer","tag-developer","tag-sql"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pbVg43-G","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":0,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"wp:attachment":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}