回显 LEFT() 查询
Echoing LEFT() query
我有这个 SQL 查询,它按原样完美运行,我现在的问题是我不能 echo
它,因为它在 LEFT()
中使用
这是完整的代码。
$empid='D001'
$sql = "Select
DISTINCT TOP 1
LEFT (employeeidno, 4) as deptcode,
RIGHT(employeeidno, 7) as empno
FROM employeemasterfile
WHERE
LEFT (employeeidno, 4)='D001'
ORDER BY
RIGHT(employeeidno, 7) DESC";
include 'query/sqlsrv_query-global.php';
if(sqlsrv_num_rows($query) > 0) {
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) {
$accountcode=$row['deptcode'] + 1;
echo "<option value='".$row['deptcode'].":".$accountcode."'>".$row['deptcode']."</option>";
}
}
有办法解决这个问题吗?我尝试使用 AS
,不幸的是没有成功。
如果您正在尝试获取下一个员工编号,那么
$accountcode=$row['deptcode'] + 1;
as $row['deptcode']
is D001
将产生警告
Warning: A non-numeric value encountered in ...
结果将是 1
。
如果你这样做
$row['deptcode']++;
这将正确调整它,您将得到 D002
我有这个 SQL 查询,它按原样完美运行,我现在的问题是我不能 echo
它,因为它在 LEFT()
这是完整的代码。
$empid='D001'
$sql = "Select
DISTINCT TOP 1
LEFT (employeeidno, 4) as deptcode,
RIGHT(employeeidno, 7) as empno
FROM employeemasterfile
WHERE
LEFT (employeeidno, 4)='D001'
ORDER BY
RIGHT(employeeidno, 7) DESC";
include 'query/sqlsrv_query-global.php';
if(sqlsrv_num_rows($query) > 0) {
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) {
$accountcode=$row['deptcode'] + 1;
echo "<option value='".$row['deptcode'].":".$accountcode."'>".$row['deptcode']."</option>";
}
}
有办法解决这个问题吗?我尝试使用 AS
,不幸的是没有成功。
如果您正在尝试获取下一个员工编号,那么
$accountcode=$row['deptcode'] + 1;
as $row['deptcode']
is D001
将产生警告
Warning: A non-numeric value encountered in ...
结果将是 1
。
如果你这样做
$row['deptcode']++;
这将正确调整它,您将得到 D002