{"id":160,"date":"2024-01-10T12:55:00","date_gmt":"2024-01-10T10:55:00","guid":{"rendered":"http:\/\/130.61.57.200\/?p=160"},"modified":"2024-01-30T11:29:06","modified_gmt":"2024-01-30T09:29:06","slug":"create-sql-loader-control-file-from-sql-server-tables","status":"publish","type":"post","link":"http:\/\/130.61.57.200\/index.php\/2024\/01\/10\/create-sql-loader-control-file-from-sql-server-tables\/","title":{"rendered":"Create SQL Loader Control file from SQL Server Tables"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">with cols as (<br>select s.name,st.name table_name,ac.name column_name,t.name column_type,ac.max_length,ac.precision,ac.scale,<br>case<br>when t.name in (&#8216;datetime&#8217;,&#8217;datetime2&#8242;,&#8217;date&#8217;) then &#8216;DATE&#8217;<br>end oracle_type<br>from sys.all_columns ac join sys.types t on t.system_type_id=ac.system_type_id<br>join sys.tables st on st.object_id=ac.object_id<br>join sys.schemas s on s.schema_id=st.schema_id<br>where st.name!=&#8217;sysdiagrams&#8217;<br>),<br>grp as<br>(select upper(table_name) table_name, col= upper(STUFF (<br>(SELECT &#8216;,&#8217; + column_name+&#8217; &#8216;+isnull(oracle_type,&#8221;) from cols t1 where t1.table_name=t2.table_name for XML PATH(&#8221;)),1,1,&#8221;)) from cols t2<br>group by table_name)<br>select &#8216;LOAD DATA<br>INFILE &#8220;&#8216;+table_name +&#8217;.csv&#8221; &#8220;str &#8221;EOL&#8221;&#8221;<br>TRUNCATE<br>INTO TABLE &#8216; +table_name +&#8217;<br>FIELDS CSV WITH EMBEDDED<br>DATE FORMAT &#8220;YYYY-MM-DD HH24:MI:SS.FFF&#8221;<br>(&#8216;+col+&#8217;)&#8217;<br>from grp<\/p>\n","protected":false},"excerpt":{"rendered":"<p>with cols as (select s.name,st.name table_name,ac.name column_name,t.name column_type,ac.max_length,ac.precision,ac.scale,casewhen t.name in (&#8216;datetime&#8217;,&#8217;datetime2&#8242;,&#8217;date&#8217;) then &#8216;DATE&#8217;end oracle_typefrom sys.all_columns ac join sys.types t on t.system_type_id=ac.system_type_idjoin sys.tables st on st.object_id=ac.object_idjoin sys.schemas s on s.schema_id=st.schema_idwhere st.name!=&#8217;sysdiagrams&#8217;),grp as(select upper(table_name) table_name, col= upper(STUFF ((SELECT &#8216;,&#8217; + column_name+&#8217; &#8216;+isnull(oracle_type,&#8221;) from cols t1 where t1.table_name=t2.table_name for XML PATH(&#8221;)),1,1,&#8221;)) from cols t2group by table_name)select &#8216;LOAD DATAINFILE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":104,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mssql","category-oracle"],"blocksy_meta":[],"_links":{"self":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":4,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":170,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/160\/revisions\/170"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media\/104"}],"wp:attachment":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}