Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2013
    Posts
    2

    Unanswered: db2 as400 declare variables

    Hey there,

    I am a newby to db2 therefore I need to ask how I can declare variables,

    my query at the moment looks like this:

    SELECT
    --FDBCLI

    to_date(concat(left(FDBCLI.CLDTOU,2),concat('/',concat(substring(FDBCLI.CLDTOU,3,2),concat('/',concat('20',right( FDBCLI.CLDTOU,2)))))),'dd/mm/yyyy')


    FROM

    FDBCLI

    I would like to declare "to_date(concat(left(FDBCLI.CLDTOU,2),concat('/',concat(substring(FDBCLI.CLDTOU,3,2),concat('/',concat('20',right( FDBCLI.CLDTOU,2)))))),'dd/mm/yyyy')" as a variable, could not find anything helpful in the forum yet, would highly appreciate it, if somebody can help.

    Thank you,

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    look at
    CREATE PROCEDURE (SQL)
    or at the samples below sqllib/samples
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    CONCAT operators might be easier to build/undersand the code than (nested) CONCAT functions.

    Expressions

    CONCAT

    Like this...
    to_date(left(FDBCLI.CLDTOU,2) concat '/' concat substring(FDBCLI.CLDTOU,3,2) concat '/' concat '20' concat right(FDBCLI.CLDTOU,2) , 'dd/mm/yyyy')
    or
    to_date(left(FDBCLI.CLDTOU,2) || '/' || substring(FDBCLI.CLDTOU,3,2) || '/' || '20' || right(FDBCLI.CLDTOU,2) , 'dd/mm/yyyy')
    Last edited by tonkuma; 03-27-13 at 06:08. Reason: Add links to Information Center - Expressions and CONCAT function.

  4. #4
    Join Date
    Mar 2013
    Posts
    2
    Thanks for the hints!

    I still quite don't get it,

    just a general question first maybe, is it possible in db2 to create sth like this:

    variable = o_date(left(FDBCLI.CLDTOU,2) || '/' || substring(FDBCLI.CLDTOU,3,2) || '/' || '20' || right(FDBCLI.CLDTOU,2) , 'dd/mm/yyyy')

    and going forward to use the variable in the select statement?

    select*

    variable

    from

    where

  5. #5
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

Posting Permissions

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