1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

Max stringlength from several tables?

Discussion in 'SQL - Questions and Answers' started by Roland Bengtsson, Jan 30, 2007.

  1. Dialect: SQL 92
    I have a stringfield called mCurrentStates in many tables like planprogress, planmission etc.

    How can I see the largest allocated string of mCurrentStates?
  2. Dimitar Guest

    Dialect: SQL 92
    You may want to look at the Dynamic SQL section in the documentation of your database server, if you want to dynamically construct the list of tables.
    SQL 92 includes Dynamic SQL features, and requires them from Intermediate level-conforming implementations.
    You may also want to look at the Information schema, to help you select which tables you want, also part of Intermediate SQL implementations.

    If you can statically name the tables, here is what comes to mind:
    SQL:

    select max(char_length(mcurrentstates)) from (select mcurrentstates from planprogress union select mcurrentstates from planmission union select mcurrentstates from planwhatever) t;

Share This Page