If statements within create temp table statements

  • I want to put a conditions within a create temp table statement and also a loop statement. Is this possible and how would I go about it.

    The reason I want to know this is so I dont't have a fix number of fields within my table.

    For example,

    if I have max of 20 orders from a customer

    I want 20 fields, to be available.

    Please help me

    Simon

  • Have you tried dynamic sql and global temp table combination for this??

    Prakash

    Prakash Heda
    Lead DBA Team - www.sqlfeatures.com
    Video sessions on Performance Tuning and SQL 2012 HA

  • As prakash mentioned, you could use dynamic sql.

    There is a topic in this forum (from today) called "Dynamically create tables". This should point you in the right direction to create the table you want depending on order size.

    Clive Strong

    clivestrong@btinternet.com

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply