This topic is locked
[SOLVED]

 AUTOINCREMENT FOR PHP to MS SQL

12/5/2012 4:48:42 AM
PHPRunner General questions
B
bujar.gashi author

Hi To All,
I Have used this to autoincrement in a field on php to myslq and works fine but phprunner 6.2 to SQL not working
$sql="select max(substr(case_number_kpi,12)) as mx from criminal_case where substr(case_number_kpi,10,2)=month(now()) order by mx";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$str="IPKHP";

$str2=date("Ym");

$str3=($data["mx"]+1);

$values["case_number_kpi"]="$str$str2".str_pad($str3, 5, 0, STR_PAD_LEFT);
can anyone help me how to solve this problem :
Best regards

Bujar

Sergey Kornilov admin 12/5/2012

What exactly doesn't work? Any error messages?

C
cgphp 12/5/2012
$values["case_number_kpi"] = $str . $str2 . str_pad($str3, 5, "0", STR_PAD_LEFT);
B
bujar.gashi author 12/14/2012

this part is something wrong ..$sql="select max(substr(case_number_kpi,12)) as mx from criminal_case where substr(case_number_kpi,10,2)=month(now()) order by mx";
when it try to generate number it says cannot convert varchar to int .
can someone help me to sov problem

C
cgphp 12/14/2012

Try this:

$sql="select max(CONVERT(substr(case_number_kpi,12),UNSIGNED INTEGER)) as mx from criminal_case where CONVERT(substr(case_number_kpi,10,2),UNSIGNED INTEGER)=month(now()) order by case_number_kpi";
B
bujar.gashi author 1/31/2013



Try this:

$sql="select max(CONVERT(substr(case_number_kpi,12),UNSIGNED INTEGER)) as mx from criminal_case where CONVERT(substr(case_number_kpi,10,2),UNSIGNED INTEGER)=month(now()) order by case_number_kpi";


B
bujar.gashi author 1/31/2013





HI CHRISTIAN ,
not working this code ..

there on php error says invalid carcter "')"
let me axplain , i have phprunner 6.2 and microsoft SQL 2008 R2