<?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>Question Re: Local variables and select statements? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822940#M4853783</link>
    <description>&lt;P&gt;I get error message that the variables not exist.
The declaration is what I showed in my question.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Dec 2015 16:26:37 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2015-12-14T16:26:37Z</dc:date>
    <item>
      <title>Local variables and select statements?</title>
      <link>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaq-p/13822937</link>
      <description>&lt;P&gt;If I use this in interactive it works:&lt;/P&gt;
&lt;LI-CODE lang="sql"&gt;declare @time1 time
declare &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1656877"&gt;@Time2&lt;/a&gt; time
declare @time3 time

select 
    @time1 = t_time1,
    &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1656877"&gt;@Time2&lt;/a&gt; = t_time2,
    @time3 = t_time3
from
    tblTimes 
select @time1, &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1656877"&gt;@Time2&lt;/a&gt;, @time3&lt;/LI-CODE&gt;


&lt;P&gt;But if I try to use it in a procedure I get error on the declares:&lt;/P&gt;
&lt;LI-CODE lang="sql"&gt;declare @time1 time;
declare &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1656877"&gt;@Time2&lt;/a&gt; time;
declare @time3 time;

select 
    @time1 = t_time1,
    &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1656877"&gt;@Time2&lt;/a&gt; = t_time2,
    @time3 = t_time3
from
    tblTimes;&lt;/LI-CODE&gt;


&lt;P&gt;So my question is how I do this in the best way in a procedure?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 16:11:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaq-p/13822937</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-12-14T16:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Local variables and select statements?</title>
      <link>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822939#M4853782</link>
      <description>&lt;P&gt;Please show us the procedure declaration and the error that you are seeing.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 16:14:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822939#M4853782</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2015-12-14T16:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Local variables and select statements?</title>
      <link>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822940#M4853783</link>
      <description>&lt;P&gt;I get error message that the variables not exist.
The declaration is what I showed in my question.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 16:26:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822940#M4853783</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-12-14T16:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: Local variables and select statements?</title>
      <link>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822941#M4853784</link>
      <description>&lt;P&gt;Without a create procedure block around that?&lt;BR /&gt;
No Begin End block either?&lt;/P&gt;
&lt;P&gt;If so then dbisql will execute each statement separately and your defines will go out of scope on the very next statement.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 17:20:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822941#M4853784</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-12-14T17:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Local variables and select statements?</title>
      <link>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822942#M4853785</link>
      <description>&lt;P&gt;I do not know if I unclear or not. But what I mean is that I has a working procedure which I try to add this in the beginning of the procedure:&lt;/P&gt;
&lt;LI-CODE lang="sql"&gt;declare @time1 time;
declare @time2 time;
declare @time3 time;

select 
    @time1 = t_time1,
    @time2 = t_time2,
    @time3 = t_time3
from
    tblTimes;&lt;/LI-CODE&gt;


&lt;P&gt;My question was, why do I get the error message that the variables do not exist?
Is it possible to do like this in a procedure?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2015 11:27:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822942#M4853785</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-12-15T11:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Local variables and select statements?</title>
      <link>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822938#M4853781</link>
      <description>&lt;P&gt;The "select @time1 = t_time1" is written using Transact SQL, so the procedure will have to be written using Transact SQL as well...&lt;/P&gt;
&lt;PRE&gt;CREATE PROCEDURE p AS

declare @time1 time
declare @time2 time
declare @time3 time

select 
    @time1 = t_time1,
    @time2 = t_time2,
    @time3 = t_time3
from
    tblTimes 
select @time1, @time2, @time3
go

SELECT * FROM p()
go
&lt;/PRE&gt;

&lt;P&gt;If you want to use Watcom SQL (highly recommended!) then use the INTO clause...&lt;/P&gt;
&lt;PRE&gt;CREATE PROCEDURE q()
BEGIN

declare @time1 time;
declare @time2 time;
declare @time3 time;

select 
    t_time1, t_time2, t_time3
into
    @time1, @time2, @time3
from
    tblTimes;

select 
    @time1, @time2, @time3;

END;
SELECT * FROM q();
&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Dec 2015 13:48:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/local-variables-and-select-statements/qaa-p/13822938#M4853781</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2015-12-15T13:48:30Z</dc:date>
    </item>
  </channel>
</rss>

