2013-07-29 71 views
-1

我已經將我的數據庫從MSQL轉換到MySQL,我得到以下錯誤。正確的語法的MySQL服務器版本使用附近'VARCHAR(500))

錯誤消息:您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法的線附近的「VARCHAR(500))=‘男’AND Responses.res_void = 0」使用手冊22

我不能工作的問題,它看起來對我有效嗎?有沒有MySQL不在這裏?

SELECT 
    Responses.res_col AS answer 
    ,Responses.res_created AS dateCreated 
    ,Responses.res_notes AS note 
    ,Responses.question_id AS questionID 
    ,Responses.res_id AS responseID 
    ,Responses.student_id AS studentID 
    ,Responses.res_answer AS subQuestion 
    ,Responses.survey_id AS surveyID 
    ,Responses.res_void AS void 
    ,Student.res_answer AS filter 
    FROM 
     Responses, Responses AS Student 
    WHERE 
     Responses.student_id = Student.student_id 
    AND 
     Responses.survey_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.surveyID#"> 
    AND 
     Student.survey_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.surveyID#"> 
    AND 
     Responses.question_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.questionID#">     AND 
     CAST(Student.res_answer AS VARCHAR(500)) = '#arguments.filter#' 
    AND Responses.res_void = <cfqueryparam cfsqltype="cf_sql_bit" value="#arguments.void#"> 
+0

@ ta.speot.is在哪裏?此代碼在MSSQL上運行。 – GrantU

+0

然而你把它標記爲MySQL。哪一個? – Bojangles

+1

@Bojangles閱讀OP的*第一行*:*我已將數據庫從MSQL轉換爲MySQL,並且出現以下錯誤*,因此他將查詢從MSSQL轉換爲MySQL。 – h2ooooooo

回答

2

你不能強制轉換爲VARCHAR()類型。你可以轉換爲純文本類型爲CHAR(n)

CAST(Student.res_answer AS CHAR(500)) = '#arguments.filter#' 

mysql doc,對於結果的類型可以是下列值之一:

  • BINARY[(N)]
  • CHAR[(N)]
  • DATE
  • DATETIME
  • DECIMAL[(M[,D])]
  • SIGNED [INTEGER]
  • TIME
  • UNSIGNED [INTEGER]
+0

VARCHAR是問題謝謝 – GrantU

相關問題