<?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: How to Get Source Code of an SQL View Using Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/921914#M363065</link>
    <description>&lt;P&gt;Easiest would be to use a database client like MS SQL Server Management Studio or DBeaver. Using SAS you need to get the result back to SAS in order to see it.&lt;/P&gt;
&lt;P&gt;Something along the line of below partially tested code should work. Replace DBO with the name of the database under which the view is stored.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydb sqlsvr .... dbmax_text=32767;

proc sql;
  connect using mydb;
  select * from connection to mydb
    (
      SELECT OBJECT_DEFINITION (OBJECT_ID(N'[DBO].[VWTABLE]')) AS [VIEW_DEFINITION]; 
    );
  disconnect from mydb;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I could test: The SQL Server query on a view that was available on my server and for which I had the necessary permissions.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2024 06:14:04 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-03-27T06:14:04Z</dc:date>
    <item>
      <title>How to Get Source Code of an SQL View Using Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/921906#M363059</link>
      <description>&lt;P&gt;When using Proc SQL to connect to an SQL Server database, is it possible to find the source code/SQL script that was used to create a View?&lt;/P&gt;&lt;P&gt;I thought an "execute sp_helptext" statement might work. If so, I'm not certain of the proper syntax. I thought the following would work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;connect to server&amp;nbsp;&lt;SPAN&gt;(user=userid password=password path=database_name);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;execute sp_helptext vwTable;&lt;/P&gt;&lt;P&gt;disconnect from server;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 03:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/921906#M363059</guid>
      <dc:creator>melc</dc:creator>
      <dc:date>2024-03-27T03:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to Get Source Code of an SQL View Using Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/921908#M363061</link>
      <description>&lt;P&gt;You can execute external database stored procedures via the SAS EXECUTE statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to server (user=userid password=password path=database_name);
execute(execute sp_helptext vwTable;) by server;
disconnect from server;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure what will happen to the SP output though&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 03:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/921908#M363061</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2024-03-27T03:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Get Source Code of an SQL View Using Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/921914#M363065</link>
      <description>&lt;P&gt;Easiest would be to use a database client like MS SQL Server Management Studio or DBeaver. Using SAS you need to get the result back to SAS in order to see it.&lt;/P&gt;
&lt;P&gt;Something along the line of below partially tested code should work. Replace DBO with the name of the database under which the view is stored.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydb sqlsvr .... dbmax_text=32767;

proc sql;
  connect using mydb;
  select * from connection to mydb
    (
      SELECT OBJECT_DEFINITION (OBJECT_ID(N'[DBO].[VWTABLE]')) AS [VIEW_DEFINITION]; 
    );
  disconnect from mydb;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I could test: The SQL Server query on a view that was available on my server and for which I had the necessary permissions.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 06:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/921914#M363065</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-27T06:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to Get Source Code of an SQL View Using Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/922094#M363121</link>
      <description>This worked perfectly. Thank you so much!</description>
      <pubDate>Thu, 28 Mar 2024 12:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Get-Source-Code-of-an-SQL-View-Using-Proc-SQL/m-p/922094#M363121</guid>
      <dc:creator>melc</dc:creator>
      <dc:date>2024-03-28T12:32:09Z</dc:date>
    </item>
  </channel>
</rss>

