Надеюсь, этот вопрос не является дубликатом.
У меня есть запрос, который работает на сервере SQL.Когда я пытаюсь использовать его в Codeigniter, я получаю Внутреннюю ошибку сервера (500).
Вот запрос с кодом php,
public function tnaBucketTable($filter = null){
$sql = "
SELECT TOP 500 start ,SC.status ,S.shift_id ,SC.call_id,SC.type,SC.win_end,S.job_id
,pin = CASE
WHEN pin IS NULL THEN pin_agency
ELSE pin
END
,CONVERT(VARCHAR, start, 3)+' '+CONVERT(CHAR(5), start, 108) AS start_time
,CONVERT(CHAR(5), [end], 108) AS finish_time
,guard_name = CASE guard_info
WHEN 'Agency' THEN (SELECT shortname FROM [SecurityPlatform].[dbo].[SP-Guard-Agency] WHERE pin = S.pin_agency)
ELSE (SELECT shortname FROM [SecurityPlatform].[dbo].[SP-Guard] WHERE pin = S.pin)
END
,guard_number = CASE guard_info
WHEN 'Agency' THEN (SELECT phone1 FROM [SecurityPlatform].[dbo].[SP-Guard-Agency] WHERE pin = S.pin_agency)
ELSE (SELECT phone_number FROM [SecurityPlatform].[dbo].[SP-Guard] WHERE pin = S.pin)
END
,agency_number = CASE S.guard_info
WHEN 'Agency' THEN (
SELECT contact_no_1 FROM [SecurityPlatform].[dbo].[SP-Agency] WHERE agency_id = (
SELECT agency_id FROM [SecurityPlatform].[dbo].[SP-Guard-Agency] WHERE pin = S.pin_agency
)
)
ELSE NULL
END
,C.client_name
,ST.site_name
,ST.phone_number AS site_phone
,ST.site_sin
FROM [SecurityPlatform].[dbo].[SP-Shift] S
JOIN [SecurityPlatform].[dbo].[SP-Job] J ON J.job_id = S.job_id
JOIN [SecurityPlatform].[dbo].[SP-Site] ST ON ST.site_sin = J.[sin]
JOIN [SecurityPlatform].[dbo].[SP-Client] C ON C.client_id = ST.client_id
JOIN [SecurityPlatform].[dbo].[SP-ScheduleCall] SC ON SC.shift_id = S.shift_id
JOIN [SecurityPlatform].[dbo].[SP-TrackingCall] TC ON TC.call_id = SC.call_id
WHERE S.[status] = 'Confirmed'
AND SC.[status] != 'Unconfirmed'
AND pin > 0 ORDER BY S.shift_id DESC, SC.win_end DESC";
$query = $this->db->query($sql);
return $query->result();
}
И результат с сервера Sql:
Результат из браузера:
У всех есть идеи, чтоя пропал?
Пожалуйста, спросите, нужна ли вам дополнительная информация.
Заранее спасибо.
Редактировать: var_dump ($ sql) для запроса
string(1763) " SELECT TOP 500 start ,SC.status ,S.shift_id ,SC.call_id,SC.type,SC.win_end,S.job_id ,pin = CASE WHEN pin IS NULL THEN pin_agency ELSE pin END ,CONVERT(VARCHAR, start, 3)+' '+CONVERT(CHAR(5), start, 108) AS start_time ,CONVERT(CHAR(5), [end], 108) AS finish_time ,guard_name = CASE guard_info WHEN 'Agency' THEN (SELECT shortname FROM [SecurityPlatform].[dbo].[SP-Guard-Agency] WHERE pin = S.pin_agency) ELSE (SELECT shortname FROM [SecurityPlatform].[dbo].[SP-Guard] WHERE pin = S.pin) END ,guard_number = CASE guard_info WHEN 'Agency' THEN (SELECT phone1 FROM [SecurityPlatform].[dbo].[SP-Guard-Agency] WHERE pin = S.pin_agency) ELSE (SELECT phone_number FROM [SecurityPlatform].[dbo].[SP-Guard] WHERE pin = S.pin) END ,agency_number = CASE S.guard_info WHEN 'Agency' THEN ( SELECT contact_no_1 FROM [SecurityPlatform].[dbo].[SP-Agency] WHERE agency_id = ( SELECT agency_id FROM [SecurityPlatform].[dbo].[SP-Guard-Agency] WHERE pin = S.pin_agency ) ) ELSE NULL END ,C.client_name ,ST.site_name ,ST.phone_number AS site_phone ,ST.site_sin FROM [SecurityPlatform].[dbo].[SP-Shift] S JOIN [SecurityPlatform].[dbo].[SP-Job] J ON J.job_id = S.job_id JOIN [SecurityPlatform].[dbo].[SP-Site] ST ON ST.site_sin = J.[sin] JOIN [SecurityPlatform].[dbo].[SP-Client] C ON C.client_id = ST.client_id JOIN [SecurityPlatform].[dbo].[SP-ScheduleCall] SC ON SC.shift_id = S.shift_id JOIN [SecurityPlatform].[dbo].[SP-TrackingCall] TC ON TC.call_id = SC.call_id WHERE S.[status] = 'Confirmed' AND SC.[status] != 'Unconfirmed' AND pin > 0 ORDER BY S.shift_id DESC, SC.win_end DESC"