General discussion

  • Creator
    Topic
  • #2190195

    Basic SQL (Variable column names)

    Locked

    by jheitmeyer ·

    I have this bit of code:



    UPDATE tbl_Legends
    SET _1 = ‘#description#’
    WHERE Month = ‘#month#’ and Year = ‘#year#’

    I currently have 31 if statements to make this work. It would be cleaner to use a loop. My trouble is mssql (or coldfusion?) dose not allow the use of a variable name for the column. I would like to do this.



    UPDATE tbl_Legends
    SET #x# = ‘#description#’
    WHERE Month = ‘#month#’ and Year = ‘#year#’

    I am sure this is somthing easy but I have googled for hours and only find stored procedures as a solution. Any help would be great.

All Comments

  • Author
    Replies
    • #3071445

      Use a variable for the SQL statement itself

      by tony hopkinson ·

      In reply to Basic SQL (Variable column names)

      and build it inside the loop, is the usual and easy way. Not familliar with cold fusion but if it can’t do that I’ll be shocked.

      • #3071321

        yup

        by jaqui ·

        In reply to Use a variable for the SQL statement itself

        cold fusion has support for 75 to 80% of sql, so it can do this.
        just as most well known db engines support sql 75 to 80%. none, that I have seen, support it 100% as the actual definitions / standards for sql has more capability than has been required by business.

Viewing 0 reply threads