2013-08-22 46 views
1

錯誤編號:1064'當t2.first_name <> '' 然後CONCAT(t2.first_name,' 't2.last_name)在t3.fir' 在第7行

你在你的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法在線附近'WHEN t2.first_name <> '' then CONCAT(t2.first_name,' ',t2.last_name) WHEN t3.fir'使用7

SELECT t1.*, 
    CASE 
     WHEN t2.first_name <> '' THEN CONCAT(t2.first_name, ' ', t2.last_name) 
     WHEN t3.first_name <> '' then CONCAT(t3.first_name, ' ', t3.last_name) 
     ELSE '' 
    END AS author 
FROM 
    (`forum` t1) 
    LRGY JOIN `admin_users` t2 ON `t1`.`user_id`=`t2`.`user_id` 
    LEFT JOIN `members` t3 ON `t1`.`member_id`=`t3`.`member_id` 
WHERE 
    `t1`.`member_id` = '104' AND 
    `topic` LIKE '%This is a topic%' AND 
    `CASE` 
     WHEN t2.first_name <> '' THEN CONCAT(t2.first_name,' ',t2.last_name) 
     WHEN t3.first_name <> '' then CONCAT(t3.first_name,' ',t3.last_name) 
     ELSE '' 
    END LIKE '%admin admin%' 

文件名的手冊:/home/wsddev3/public_html/dev/justice/models/forum_model.php

行號:40

+2

首先嚐試格式化你的代碼。這幾乎總是使語法錯誤顯而易見。 – RandomSeed

+0

什麼是第40行? – eatonphil

+2

這可能是'CASE'周圍的反響。嘗試刪除這些。 –

回答

1

在它具有在CASE語句中的問題是沒有'

SELECT t1.*, 
    CASE 
     WHEN t2.first_name <> '' THEN CONCAT(t2.first_name, ' ', t2.last_name) 
     WHEN t3.first_name <> '' then CONCAT(t3.first_name, ' ', t3.last_name) 
     ELSE '' 
    END AS author 
FROM 
    `forum` t1 
    LEFT JOIN `admin_users` t2 ON `t1`.`user_id`=`t2`.`user_id` 
    LEFT JOIN `members` t3 ON `t1`.`member_id`=`t3`.`member_id` 
WHERE 
    `t1`.`member_id` = '104' AND 
    `topic` LIKE '%This is a topic%' AND 
    CASE 
     WHEN t2.first_name <> '' THEN CONCAT(t2.first_name,' ',t2.last_name) 
     WHEN t3.first_name <> '' then CONCAT(t3.first_name,' ',t3.last_name) 
     ELSE '' 
    END LIKE '%admin admin%' 
相關問題