CodeIgniter Forums
A Database Error Occurred - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: A Database Error Occurred (/showthread.php?tid=73201)



A Database Error Occurred - Mohamed Rauf - 03-30-2019

[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting the varchar value 'currInstl + 1' to data type int.

SELECT "custNo", "custName", "totalInstal", "InstallAmnt" FROM "fund" WHERE "status" = 'A' AND "branch" = 16 AND "totalInstal" > 'currInstl + 1' ORDER BY "custName" ASC



Ref (Sql Query works well)
=================
select custNo, custName, totalInstal, InstallAmnt from fund
where status='A' and branch=16 and totalInstal> currInstl+ 1
order by custName;

but not to works in codeigniter..Please help me


RE: A Database Error Occurred - hc-innov - 03-30-2019

@Mohamed,
can you send your PHP code with your sql request?

Perhaps, a problem with your quotes: 'currInstl + 1'


RE: A Database Error Occurred - Mohamed Rauf - 03-30-2019

(03-30-2019, 02:54 AM)hc-innov Wrote: @Mohamed,
can you send your PHP code with your sql request?

Perhaps, a problem with your quotes:  'currInstl + 1'

public function getFund()
{
return $this->db->select('custNo, custName, totalInstal, InstallAmnt')
->from('fund')
->where('status', 'A')
->where('branch', 16)
->where('totalInstal >', 'currInstl + 1')
->order_by('custName', 'asc')
->get()
->result_array();
}


RE: A Database Error Occurred - hc-innov - 03-30-2019

You can try this

PHP Code:
public function getFund()
{
return 
$this->db->select('custNo, custName, totalInstal, InstallAmnt')
->
from('fund')
->
where('status''A')
->
where('branch'16)
->
where('totalInstal >''currInstl + 1',false)
->
order_by('custName''asc')
->
get()
->
result_array();

Note the false in where clause for totalInstall <=>The field is not protected (no quote)


RE: A Database Error Occurred - Mohamed Rauf - 03-31-2019

(03-30-2019, 11:04 AM)hc-innov Wrote: You can try this

PHP Code:
public function getFund()
{
return 
$this->db->select('custNo, custName, totalInstal, InstallAmnt')
->
from('fund')
->
where('status''A')
->
where('branch'16)
->
where('totalInstal >''currInstl + 1',false)
->
order_by('custName''asc')
->
get()
->
result_array();

Note the false in where clause for totalInstall <=>The field is not protected (no quote)

Thank you so much it's working.. Smile