大家好,我想问一下,我使用 CI 3 开发一些应用程序,我已经构建了自己的模型,但是 mysql 语法存在一些错误,如何解决这个问题,或者我的 sql 查询是错误的?
function get_ref_bidang()
{
$this->db->select("CAST(A.Kd_Urusan AS varchar(2))+'.'+RIGHT('0' + CAST(A.Kd_Bidang AS varchar(2)),2) AS Kd_Bidang_Gab");
$this->db->select("CAST(A.Kd_Urusan AS varchar(2))+'.'+CAST(A.Kd_Bidang AS varchar(2)) +' - '+ A.Nm_Bidang AS Nm_Bidang_Gab");
$this->db->from("Ref_Bidang A");
return $this->db->get()->result();
}
感谢您的帮助..谢谢
您可以尝试使用包含+
的 CONCAT 函数
Mysql 不支持CAST
可以将数据转换为char
的 varchar 数据类型
$this->db->select("CONCAT(CAST(A.Kd_Urusan AS char(2)),'.',RIGHT(CONCAT('0',CAST(A.Kd_Bidang AS char(2))),2)) AS Kd_Bidang_Gab");
$this->db->select("CONCAT(CAST(A.Kd_Urusan AS char(2)),'.',CAST(A.Kd_Bidang AS char(2)) ,' - ', A.Nm_Bidang) AS Nm_Bidang_Gab");
SQLfiddle