{"id":89,"date":"2009-10-28T15:59:38","date_gmt":"2009-10-28T15:59:38","guid":{"rendered":"http:\/\/blog.rabihtawil.com\/?p=89"},"modified":"2010-07-22T13:33:52","modified_gmt":"2010-07-22T13:33:52","slug":"how-to-insert-from-other-table-that-already-exists","status":"publish","type":"post","link":"http:\/\/www.raytawil.com\/?p=89","title":{"rendered":"How to Insert from other table that already exists"},"content":{"rendered":"<p>The basic Insert statement is.<\/p>\n<pre>CREATE TABLE Customer (\nID int identity(1,1),\nCustomerName varchar(30),\nAddress varchar(100),\nPhone varchar (100)\n)\nINSERT INTO Customer (CustomerName, Address, Phone)<\/pre>\n<p>How about you want to put or just copy some of the data from other table to this Customer Table?<\/p>\n<pre>INSERT INTO Customer (CustomerName, Address, Phone)\nSELECT CustomerName, Address, Phone From OldCustomer<\/pre>\n<p>In above query you\u2019ll insert your customer table with data from OldCustomer table with ID less than 50 (0-49).<\/p>\n<p>How about if you just want to create a replication of a table with data type?<br \/>\nOn<\/p>\n<pre>SELECT * INTO <em>newTable<\/em> FROM <em>OldTable\n\n<\/em>You don\u2019t need to create the table first. Cause on select into statement the create table is already done then the insertion.\n\nSELECT * INTO Customer FROM OldCustomer\n\nHow about if you just want to create a replication of some column in a table and columns\u2019 data type?\n\nSELECT CustomerName, Phone INTO Customer FROM OldCustomer\n\nAnd if there are needs to use join or where clause just use it as you need it. <img decoding=\"async\" class=\"wp-smiley\" src=\"http:\/\/s.wordpress.com\/wp-includes\/images\/smilies\/icon_smile.gif\" alt=\":)\" \/>\n\nexample :\n\nSELECT A.CustomerName, A.Phone, B.City INTO Customer\nFROM OldCustomer A JOIN City B On A.CityID= B.CityID\nWHERE City LIKE ':%'\n\nINSERT INTO Customer (CustomerName, Address, Phone)\nSELECT CustomerName, Address, Phone From OldCustomer A\nJOIN City B On A.CityID= B.CityID\nWhere A.ID &gt; 50\nAND City LIKE 'L%'<\/pre>\n<pre>Where ID &gt; 50<\/pre>\n<pre>values ('Jane', 'anywhere street', '9097655')<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The basic Insert statement is. CREATE TABLE Customer ( ID int identity(1,1), CustomerName varchar(30), Address varchar(100), Phone varchar (100) ) INSERT INTO Customer (CustomerName, Address, Phone) How about you want to put or just copy some of the data from other table to this Customer Table? INSERT INTO Customer (CustomerName, Address, Phone) SELECT CustomerName, Address, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[112],"tags":[],"_links":{"self":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/89"}],"collection":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":1,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":168,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions\/168"}],"wp:attachment":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}