Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2014
    Posts
    3

    Unanswered: select with double quote (") on column name

    Hi,
    Example:
    I'm trying to select a table using this select statement:

    select "00001" from tablename;

    when I'm trying to run this statement it runs perfectly,
    but here's the problem, when I'm trying this:

    declare v_col varchar(100);
    set v_col = '"00001"'
    select v_col from tablename;

    and the result is "00001", but the real value for that column is not the same as the column name. btw I'm using stored procedure for this statement.

    Thanks for help.

  2. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    you have to use dynamic sql, not static.
    Code:
    declare v_col varchar(100);
    declare c1 cursor for s1;
    
    set v_col = '"00001"'
    prepare s1 from 'select ' ||v_col||' from tablename';
    open c1;
    fetch c1 into ...;
    Regards,
    Mark.

  3. #3
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    db2 version platform ?
    describe the table...
    show the sql as executed in command window with result
    show the execute of sp with result/messages from command line
    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

  4. #4
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    also, take a look around, I think I just saw something the other day on planet DB2 about quotes
    Dave

Posting Permissions

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