Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2015

    Question Unanswered: SQL if column exists use column else use ' '

    Hi all, I'm currently working on creating a Microsoft SSIS solution and I'm looking for some help creating a query against some db2 tables.
    I have a whole bunch of tables, 1 table for each product line to be correct.
    I want to loop through these tables by inputing the current line as a parameter (this is solved) but I need som help with another issue.

    Lets say we have:
    ProductLine1 with columns LENGHT varchar(10), and WIDTH varchar (10)
    ProductLine2 with columns HEIGHT varchar(10), and WIDTH varchar (10)

    In the select statement I would like to do the following:

    Select case when LENGTH exists in SYSIBM.SYSCOLUMNS
    then use column LENGTH
    ELSE '' as LENGHT
    case when WIDTH exists in SYSIBM.SYSCOLUMNS
    then use column WIDTH
    ELSE '' as WIDTH
    and so on...

    The reason why I don't want to create a new query (dataflow) for each table is that we have roughly 70
    different product lines so whenever we for instance want to add a new column we don't want to add it in 70 queries

    Do you have any ideas how to do this in an effective way?

    Best regards
    Last edited by SSISMats; 12-08-15 at 15:28.

  2. #2
    Join Date
    Apr 2008
    Iasi, Romania
    Provided Answers: 2
    You may build the query dynamic, by concatenating strings, and at the end run it with EXECUTE IMMEDIATE
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  3. #3
    Join Date
    Dec 2015
    Thanks for your anwer, I'll have to look into that

Posting Permissions

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