General discussion

Locked

Basic SQL (Variable column names)

By jheitmeyer ·
I have this bit of code:

<cfif day eq '_1'>
<cfquery name = "update" dataSource = "KFS">
UPDATE tbl_Legends
SET _1 = '#description#'
WHERE Month = '#month#' and Year = '#year#'
</cfquery>

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.

<cfif day eq #x#>
<cfquery name = "update" dataSource = "KFS">
UPDATE tbl_Legends
SET #x# = '#description#'
WHERE Month = '#month#' and Year = '#year#'
</cfquery>

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 conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Use a variable for the SQL statement itself

by Tony Hopkinson In reply to Basic SQL (Variable colum ...

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.

Collapse -

yup

by Jaqui In reply to Use a variable for the SQ ...

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.

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums