Stored Procedure updating columns Dynamically
Posted on 2012-04-02
I have a stored procedure that I want to have save a value to a column based on the input I throw at it. I'm checking for existing column and datatype.
,@ColumnDataType VARCHAR(255) OUTPUT
SELECT @ColumnDataType = [Data_Type]
IF @ColumnDataType <> ''
----- @ColumnDataType here is set to a value of 'bit'
SET @ColumnName =@ColumnValue
,[Modified_Timestamp] = CURRENT_TIMESTAMP
,[Modified_Action] = 'Update'
WHERE [Registration_ID] = @Registration_ID
However when I run the SP, it does not update the column to the value I supply.
I tried using CAST with a dynamic SQL but it ended up in misery, so I'm avoiding that route unless I have to.
The SQL I used was:
SET @ColumnName = CAST(@ColumnValue AS @ColumnDataType)
Any suggestions as to what I'm doing wrong?