$result = mssql_query('SELECT substr('1234567890', 1,4) as fld_1234, substr('1234567890', 5,3) as fld_567
C001 FROM T001 WHERE User=\''.$GLOBALS['user'].'\'');
list($C001)=mssql_fetch_row($result);
$result2=$result;
ใช้ Function LEFT เอาครับจะเอากี่ตัวก็ระบุเอาครับ Code (PHP)
<?php
$result = mssql_query('SELECT LEFT(C001,4) AS SUB_C001 FROM T001 WHERE User=\''.$GLOBALS['user'].'\'');
list($C001)=mssql_fetch_row($result);
$result2=$result;
?>
$result = mssql_query('SELECT LEFT(C001,4) AS SUB_C001 FROM T001 WHERE User=\''.$GLOBALS['user'].'\'');
list($C001)=mssql_fetch_row($result);
$result2=$result;
$sql="Update T001 Set C001 = '".$result2."'0274548 WHERE User=\''.$GLOBALS['user'].'\''
$query=mssql_query($sql);
$result = mssql_query('SELECT LEFT(C001,4) AS SUB_C001 FROM T001 WHERE User=\''.$GLOBALS['user'].'\'');
list($C001)=mssql_fetch_row($result);
$result2=$result;
$sql="Update T001 Set C001 = '".$result2."'0274548 WHERE User=\''.$GLOBALS['user'].'\''
$query=mssql_query($sql);
$result = mssql_query('SELECT LEFT(C001,4) AS SUB_C001 FROM T001 WHERE User=\''.$GLOBALS['user'].'\'');
list($C001)=mssql_fetch_row($result);
$result2=$result;
$AAA = $result2."0274548";
$sql="Update T001 Set C001 = '$AAA' WHERE User=\''.$GLOBALS['user'].'\''
$query=mssql_query($sql);
และโค๊ดทั้งหมดนี้ที่คุณเขียนมา
$result = mssql_query('SELECT LEFT(C001,4) AS SUB_C001 FROM T001 WHERE User=\''.$GLOBALS['user'].'\'');
list($C001)=mssql_fetch_row($result);
$result2=$result;
$sql="Update T001 Set C001 = '".$result2."'0274548 WHERE User=\''.$GLOBALS['user'].'\''
$query=mssql_query($sql);
เขียนได้แบบนี้ครับ
Code (PHP)
$sql="Update T001 Set C001 =CONCAT( LEFT(C001,4), '0274548') WHERE User='$GLOBALS[user]' ";
$query=mssql_query($sql);