/*
 * 连接到数据库
 */
$db_host = "××××";
$db_user = "××";
$db_passwd = "×××";
$db_dbName = "××";
$PersistentConnection = 1 ;
$db_type ="sybase";
$db_proto ="";
$db_options = "";
$db = DB::connect("$db_type://$db_user:$db_passwd@$db_host/$db_dbName");
$strSql="select 
(case when (select max(barcode) from comm_barcode where code = a.code) <> '' then (select max(barcode) from comm_barcode where code = a.code) else '无条码' end ) as '条形码',
b.name as '品名',
b.spec as '规格',
b.unit as '单位',
a.amount '销售数量'
from account a,
commodity b
 where a.depart = '$sel_md'
 and a.sort like '$sel_lb%' 
 and a.busdate between '$ksrq' and '$jsrq'
and a.code = b.code;";
//print ("$strSql");
$str= MagExecute($strSql);        //执行SQL发生数据库错误:syntax error
--------------------------------------------------------------------------------
select (case when (select max(barcode) from comm_barcode where code = a.code) <> '' then (select max(barcode) from comm_barcode where code = a.code) else '无条码' end ) as '条形码', b.name as '品名', b.spec as '规格', b.unit as '单位', a.amount '销售数量' from account a, commodity b where a.depart = '0102' and a.sort like '01%' and a.busdate between '2008-5-28' and '2008-5-29' and a.code = b.code;