<?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 use EXECUTE sp_executesql  @Query in SAS in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-to-use-EXECUTE-sp-executesql-Query-in-SAS/m-p/722764#M27921</link>
    <description>&lt;P&gt;Looks like it is working OK then. The SAS EXECUTE statement runs SQL but doesn't produce any result set. If you want to see a result set then you need to get the stored procedure to create a temporary SQL Server table, then query the temporary table in a following SQL SELECT query.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Mar 2021 02:20:06 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2021-03-02T02:20:06Z</dc:date>
    <item>
      <title>how to use EXECUTE sp_executesql  @Query in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-use-EXECUTE-sp-executesql-Query-in-SAS/m-p/722761#M27920</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;I have some complex sql code&amp;nbsp; to run from SAS, currently its working in SQL server but not from SAS. I tried simple SELECT SQL to execute from PROC sql with Execute odbc. its not giving any error and warning and no output&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;do you suggest what could be the problem&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;Proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;connect&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; odbc(DSN=&amp;amp;DSN user=&amp;amp;user password=&amp;amp;pwds);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;Execute&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (DECLARE @Query NVARCHAR(MAX) = &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;''&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Set @Query=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'select distinct qrm_db from [FASTControl].[dbo].ALM_NVPData&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;PRINT @Query&lt;/P&gt;&lt;P&gt;sp_executesql @Query&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; odbc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Writing HTML(EGHTML) Body file: EGHTML&lt;/P&gt;&lt;P&gt;23 FILENAME EGXLSSX TEMP;&lt;/P&gt;&lt;P&gt;24 ODS EXCEL(ID=EGXLSSX) FILE=EGXLSSX STYLE=Excel&lt;/P&gt;&lt;P&gt;25 OPTIONS (&lt;/P&gt;&lt;P&gt;26 EMBEDDED_TITLES="no" EMBEDDED_FOOTNOTES="no"&lt;/P&gt;&lt;P&gt;27 );&lt;/P&gt;&lt;P&gt;28&lt;/P&gt;&lt;P&gt;29 GOPTIONS ACCESSIBLE;&lt;/P&gt;&lt;P&gt;30 Proc SQL;&lt;/P&gt;&lt;P&gt;31 connect to odbc(DSN=&amp;amp;DSN user=&amp;amp;user password=&amp;amp;pwds);&lt;/P&gt;&lt;P&gt;32 Execute (DECLARE @Query NVARCHAR(MAX) = ''&lt;/P&gt;&lt;P&gt;33 Set @Query='select distinct qrm_db from [FASTControl].[dbo].ALM_NVPData&lt;/P&gt;&lt;P&gt;34 PRINT @Query&lt;/P&gt;&lt;P&gt;35 sp_executesql @Query&lt;/P&gt;&lt;P&gt;36 ') by odbc;&lt;/P&gt;&lt;P&gt;37 quit;&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.12 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.05 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 02:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-use-EXECUTE-sp-executesql-Query-in-SAS/m-p/722761#M27920</guid>
      <dc:creator>Ashpak</dc:creator>
      <dc:date>2021-03-02T02:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to use EXECUTE sp_executesql  @Query in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-use-EXECUTE-sp-executesql-Query-in-SAS/m-p/722764#M27921</link>
      <description>&lt;P&gt;Looks like it is working OK then. The SAS EXECUTE statement runs SQL but doesn't produce any result set. If you want to see a result set then you need to get the stored procedure to create a temporary SQL Server table, then query the temporary table in a following SQL SELECT query.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 02:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-use-EXECUTE-sp-executesql-Query-in-SAS/m-p/722764#M27921</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-02T02:20:06Z</dc:date>
    </item>
  </channel>
</rss>

