<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating sql table with varchar(Max) using ODBC in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506451#M135779</link>
    <description>We unfortunately only have ODBC licensed, no OLE DB or Microsoft SQL...</description>
    <pubDate>Mon, 22 Oct 2018 14:20:55 GMT</pubDate>
    <dc:creator>js5</dc:creator>
    <dc:date>2018-10-22T14:20:55Z</dc:date>
    <item>
      <title>Creating sql table with varchar(Max) using ODBC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506437#M135772</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having issues creating character variables longer than 8000 characters in an SQL odbc library. We need to transfer several sas datasets into an SQL database and I have written the following macro to accomplish the task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro transfer_to_sql;

	libname aaa odbc prompt="Driver={ODBC Driver 13 for SQL Server};
		Server=xxxx;
		Database=xxxx;
		Trusted_Connection=yes;"
		bulkload=yes;

		proc sql noprint;
			%do i = 1 %to &amp;amp;last_dataset;
				drop table aaa.&amp;amp;&amp;amp;dataset&amp;amp;i;
				select cats(name, %str("='varchar(max)'")) 
					into :varcharmax separated by " "
						from dictionary.columns where libname="bbb"
							and memname=upcase("&amp;amp;&amp;amp;dataset&amp;amp;i")
							and type="char"
							and length GT 8000;

				%if &amp;amp;sqlobs GT 0 %then
					%do;
						create table aaa.&amp;amp;&amp;amp;dataset&amp;amp;i(dbtype=(&amp;amp;varcharmax)) as 
							select * from bbb.&amp;amp;&amp;amp;dataset&amp;amp;i;
					%end;
				%else
					%do;
						create table aaa.&amp;amp;&amp;amp;dataset&amp;amp;i as 
							select * from bbb.&amp;amp;&amp;amp;dataset&amp;amp;i;
					%end;
			%end;
		quit;

	libname aaa clear;

%mend transfer_to_sql;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It works up to a point where a variable longer than 8000 characters is encountered, then the following error happens:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ERROR: Error binding parameters: [Microsoft][ODBC Driver 13 for SQL Server]Invalid field size for datatype&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Disabling the bulk loader does not help much, the error message is different though:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ERROR: Error binding parameters: [Microsoft][ODBC Driver 13 for SQL Server]Invalid precision value&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Has anyone seen this before? Is there a solution available? Thank you for your support in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506437#M135772</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2018-10-22T13:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sql table with varchar(Max) using ODBC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506443#M135775</link>
      <description>&lt;P&gt;&amp;nbsp;A google search for "odbc varchar max length" lets me think you may have hit on a problem with the ODBC driver for MS SQL.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 13:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506443#M135775</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-22T13:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sql table with varchar(Max) using ODBC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506446#M135777</link>
      <description>It certainly is looking this way. In the meantime I have tried the old "SQL Server" driver (one shipped with Windows 7) and it appears to have succeeded with bulk loader disabled - albeit it took a long time. With bulk loader enabled it fails in the same way the version 13 driver did.&lt;BR /&gt;I requested to have version 17.2 installed, let's see if that helps.</description>
      <pubDate>Mon, 22 Oct 2018 14:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506446#M135777</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2018-10-22T14:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sql table with varchar(Max) using ODBC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506450#M135778</link>
      <description>&lt;P&gt;My guess is ODBC is not recognizing the varchar of this size. Try using SQL server native driver or OLEDB instead of ODBC.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 14:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506450#M135778</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-10-22T14:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sql table with varchar(Max) using ODBC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506451#M135779</link>
      <description>We unfortunately only have ODBC licensed, no OLE DB or Microsoft SQL...</description>
      <pubDate>Mon, 22 Oct 2018 14:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506451#M135779</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2018-10-22T14:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sql table with varchar(Max) using ODBC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506453#M135780</link>
      <description>&lt;P&gt;I was able to update the macro to use the venerable driver from 2010 and enable bulkloading only if there are no values longer than 8000 characters:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro transfer_to_sql;
	
	libname aaa odbc prompt="Driver={SQL Server};
		Server=xxxx;
		Database=xxxx;
		Trusted_Connection=yes;";

		proc sql noprint;
			%do i = 1 %to &amp;amp;last_dataset;
				drop table aaa.&amp;amp;&amp;amp;dataset&amp;amp;i;
				select cats("'", name, "'n='varchar(max)'") 
					into :varcharmax separated by " "
						from dictionary.columns where libname="bbb"
							and memname=upcase("&amp;amp;&amp;amp;dataset&amp;amp;i")
							and type="char"
							and length GT 8000;

				%if &amp;amp;sqlobs GT 0 %then
					%do;
						create table aaa.&amp;amp;&amp;amp;dataset&amp;amp;i(dbtype=(&amp;amp;varcharmax)) as 
							select * from bbb.&amp;amp;&amp;amp;dataset&amp;amp;i;
					%end;
				%else
					%do;
						create table aaa.&amp;amp;&amp;amp;dataset&amp;amp;i(bulkload=yes) as 
							select * from bbb.&amp;amp;&amp;amp;dataset&amp;amp;i;
					%end;
			%end;
		quit;

	libname aaaclear;

%mend transfer_to_sql;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I will test more once I get the latest 17.2 ODBC driver installed and report back.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 14:25:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/506453#M135780</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2018-10-22T14:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating sql table with varchar(Max) using ODBC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/507081#M136031</link>
      <description>&lt;P&gt;With ODBC driver 17.2 the things are better in some aspects but worse in others:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;with bulkload set to no and no varchar(max) defined I can load everything into the database, character variables longer than 8000 bytes end up loaded as text (this was the same with driver version 13)&lt;/LI&gt;&lt;LI&gt;with bulkload set to no and varchar(max) set I am still getting the invalid precision value error&lt;/LI&gt;&lt;LI&gt;with bulkload set to yes sas crashes,&amp;nbsp;no matter whether variables longer&amp;nbsp;than 8000 bytes are involved or not - this is a change from driver version 13 which was throwing the "Invalid field size for datatype" error with long variables and working correctly with short ones.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I will keep investigating.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 08:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-sql-table-with-varchar-Max-using-ODBC/m-p/507081#M136031</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2018-10-24T08:45:46Z</dc:date>
    </item>
  </channel>
</rss>

