1

My requirement is to fetch value from mysql table by passing column names dynamically which I get from function. But the problem is, it displays it as it is rather then fetching the value of column. The select query is:

SET @stqry =
    CONCAT('SELECT DISTINCT 
    FD.FormsDataID AS FormDataID,
    FC.ColumnName AS FieldName,
    IFNULL(FC.CustomDisplayName,FC.ColumnName) AS DisplayName,
    GetColumnValue(',_FormID,',FC.ColumnName) AS FieldValue,
    GetColumnValue(FC.FormID,FC.ColumnName) AS ColIndex
    FROM FormsData FD 
    LEFT JOIN FormsColumns FC ON FD.FormID = FD.FormID
    LEFT JOIN FormsRelationship FR ON FR.FormID = FC.FormID
    WHERE FD.FormID = ',_FormID,' AND FD.ID = ',_recordID
    ,' AND FC.FormID=',_FormID
    ,' AND FD.PARENT_RECORD_ID = 0 AND FC.IsDisplayInEmail = 1
    AND FC.IsActive = 1');
    select @stqry;

    PREPARE n_StrSQL FROM @stqry;
    EXECUTE n_StrSQL;

GetColumnValue()is the function I've made which returns columnname from table.(I need it because columns names are added by user dynamically). The result I am getting is:

FormDataID FieldName fieldValue
-------------------------------
2497       date_time  [1]
2497       auto_email [2]
2497       more_email [3]

But actual result should fetch values of [1],[2],[3] in third column. What am I missing here?Can any one help?

4

0 回答 0