General discussion
October 4, 2005 at 09:41 AM
jheitmeyer

Basic SQL (Variable column names)

by jheitmeyer . Updated 21 years ago

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.

This discussion is locked

All Comments