Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:15:28+00:00 2026-06-16T01:15:28+00:00

Is there any way to submit dynamically generated SQL to Teradata? I’ve written a

  • 0

Is there any way to submit dynamically generated SQL to Teradata? I’ve written a query that will create the code to denormalize a table. Right now, I am pulling the code down to my client (SAS) and resubmitting it in a second step. I am not familiar with either Teradata macros or procedures; would something like that work?

To illustrate, I have a table defined like this:

create multiset table MYTABLE
    (  RECID  integer generated always as identity
              ( start with 1
               increment by 1
               minvalue -2147483647
               maxvalue 2147483647
               no cycle )
     , SNAP_DATE  date format 'YYYY/MM/DD'
     , EMAIL_DATE date format 'YYYY/MM/DD'
     , FREQ integer
    )
unique primary index ( RECID  )

The table is populated every day (SNAP_DATE) and is used to monitor changes to an email_date in another table. The following query returns the code that I can run to create my denormalized view:

select RUN_THIS
from (
    select RUN_THIS, RN
    from (
        select 'select EMAIL_DATE ' (varchar(100)) as RUN_THIS
              , 0 (int) as RN
          ) x

    union all
    select ', sum( case when SNAP_DATE = date '''
             || (SNAP_DATE (format 'yyyy-mm-dd') (char(10)) )
             || ''' then FREQ else 0 end ) as D'
             || (SNAP_DATE (format 'yyyymmdd') (char(8)) ) as RUN_THIS
          , row_number() over ( partition by 1 order by SNAP_DATE ) as RN
    from ( select distinct SNAP_DATE 
           from MYTABLE 
           where SNAP_DATE > current_date - 30) t1

    union all
    select RUN_THIS, RN
    from (
        select 'from MYTABLE group by 1 order by 1;' as RUN_THIS
                , 10000 as RN
          ) y
    ) t
order by RN

I export the result of the above query to a file on my client, then turn around and submit that file back to Teradata. I’m hoping there is some way to store this complete definition in some Teradata object so it can be executed directly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:15:30+00:00Added an answer on June 16, 2026 at 1:15 am

    You may find success putting this in a stored procedure using the DBC.SysExecSQL command.

    Here is an overly simplified example of a stored procedure in Teradata. Obviously in production would want an error handler defined to address things like invalid database objects. Furthermore, you could return the SQLSTATE back as a parameter to test for whether the stored procedure completed successfully or not.

    CREATE PROCEDURE SYSDBA.CommentDatabase
    (
      IN P_Database VARCHAR(30),
      IN P_Comment VARCHAR(255), 
      OUT MSG
    )
    MAIN:  --Label
    BEGIN
    
      DECLARE  P_SQL_TEXT     VARCHAR(4000);
    
      SET P_SQL_TEXT='COMMENT ON DATABASE '||P_DATABASE||' AS '''||P_COMMENT||'''';
      CALL dbc.SysExecSQL (:P_SQL_TEXT);
    
      SET MSG = 'Database '||P_DBNAME||' commented successfully!';
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can set a formatter on models that will convert
Is there any way to create forms for a particular content type and submit
Is there any way to achieve compiling Node.js scripts as native code, like Hip-Hop
Is there any way to stop or terminate long running Oracle query in JDBC
Is there any way to submit a form when a user clicks on a
Is there a way to submit an HTML form using JavaScript that is guaranteed
I have a form that is generated dynamically. The end users will be able
Is there any way to when you click submit on a form, as each
$('form').each(function(){ var form = this; $('a', this).click(function(){ form.submit(); }); }); Is there any way
Is there any way to set post parameters? When i submit a form I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.