Results 1 to 2 of 2
  1. #1
    Join Date
    May 2012
    Posts
    155

    Unanswered: To pass Variable value in a sql-Script

    Hallo everyone,

    in my SQL Script script.sql, I am using a variable from type date. This date should be the date as the sql-script being run. I am using:

    Code:
    db2 -td@ -vf ./script.sql || exit 1
    to run the sql-script.

    A fragment of the sql-code looks like below:

    Code:
    ...
    ...
    
    select 
     	current date, coalesce(dub_skz||dub_akz, '-'), count(*)
    from 
    	mySchema.myTable
    group by
    	string1||String1;
    ...
    ...
    How can I make current date as a date as the shell command
    Code:
    db2 -td@ -vf ./script.sql || exit 1
    is being run?

    I somehow need to pass the date variable from shell to the sql-script. Is it possible without using the prefix db2 at all the lines in my sql-script?

    Thank you for the advice.

    Regards,

    Ratna

  2. #2
    Join Date
    Mar 2003
    Posts
    280
    You can use a dummy value such as @@mydate@@ in the sql file, and then replace it with sed (assuming unix)

    sed -e "s/@@mydate@@/.../g" < script.sql > script2.sql

    Then execute the new file

Posting Permissions

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