Results 1 to 5 of 5
  1. #1
    Join Date
    May 2011
    Posts
    11

    Unanswered: How To Create Variable?

    I'm new to DB2 syntax. Is the below syntax correct for create new variable to be consumed by subsequent queries?

    CREATE VARIABLE MKTG.TheDate VARCHAR(10) ;
    SET TheDate = '2011-05-02' ;
    SELECT TheDate,* FROM MKTG.LAWMAPPING

    What kind of permission do I need to create a variable?
    Thanks!

  2. #2
    Join Date
    Apr 2011
    Posts
    19
    you know you can select "current date" or "current time" right?

    But here are some examples:

    DB2 Database for Linux, UNIX, and Windows

  3. #3
    Join Date
    May 2011
    Posts
    11
    I am creating variables other than dates, so would need to know how to correctly create bunch of variable names.

    I'm getting permission erorr when executing the following syntax.
    What kind of permission do I need? I just want local variable that can be used during a batch run (ie declare @str varchar(255) set @str='partner')

    Is there a local variable example? or do I have to create variables objects in the schema itself?

    CREATE VARIABLE MKTG.STR VARCHAR(10) ;

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by captainlaw View Post
    I just want local variable that can be used during a batch run (ie declare @str varchar(255) set @str='partner')
    May be what you need is a compound SQL statement?

    Compound SQL (compiled) - IBM DB2 9.7 for Linux, UNIX, and Windows

  5. #5
    Join Date
    May 2011
    Posts
    11
    I tried your suggestion of Compound SQL. See my script below. I'm get declare syntax error. Can someone provide syntax for my logic below?

    declare lawint INTEGER default 0;
    declare lawstring VARCHAR(255) default 'lebron';
    while lawint<3
    begin
    print lawstring+cast(lawint as varchar(10))
    set lawint=lawint+1
    end

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •