{"id":495,"date":"2014-02-20T09:35:59","date_gmt":"2014-02-20T14:35:59","guid":{"rendered":"http:\/\/www.cfchimp.com\/wordpress\/?p=495"},"modified":"2024-12-05T20:16:26","modified_gmt":"2024-12-06T01:16:26","slug":"sql-server-select-into-existing-table","status":"publish","type":"post","link":"https:\/\/csimmons.dev\/blog\/2014\/02\/sql-server-select-into-existing-table\/","title":{"rendered":"SQL Server SELECT into existing table"},"content":{"rendered":"<p>This morning I needed to add a single record to an existing table in database1 from an existing table in database2.  Here&#8217;s how I was able to do it:<\/p>\n<pre class=\"prettyprint\">\r\nINSERT INTO database1.dbo.tablename\r\n     SELECT *  \r\n     FROM \r\n          database2.dbo.tablename\r\n     WHERE \r\n          ID='4d08aeb0bedd01452dfef3eabc2816dcc75533c8'\r\n<\/pre>\n<p><em>Please note that the databases use a SHA-1 Hash for the ID field.  If you use an IDENTITY field in SQL you&#8217;d have to take some extra steps to briefly allow inserting an IDENTITY field.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This morning I needed to add a single record to an existing table in database1 from an existing table in database2. Here&#8217;s how I was able to do it: INSERT INTO database1.dbo.tablename SELECT * FROM database2.dbo.tablename WHERE ID=&#8217;4d08aeb0bedd01452dfef3eabc2816dcc75533c8&#8242; Please note that the databases use a SHA-1 Hash for the ID field. If you use an &#8230; <a title=\"SQL Server SELECT into existing table\" class=\"read-more\" href=\"https:\/\/csimmons.dev\/blog\/2014\/02\/sql-server-select-into-existing-table\/\" aria-label=\"Read more about SQL Server SELECT into existing table\">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-495","post","type-post","status-publish","format-standard","hentry","category-developer","tag-developer","tag-sql"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pbVg43-7Z","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/495","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=495"}],"version-history":[{"count":0,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/495\/revisions"}],"wp:attachment":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/media?parent=495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/categories?post=495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/tags?post=495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}