简体   繁体   中英

Combine DBGrid column values

I have a DBGrid component of BDS 2006 in my application. The snapshot of the grid is as follows.

在此处输入图片说明

The DBGrid component is connected to a MySQL database, which gets populated at run time. The query I have used is:

dm.MyQpayment.SQL.Clear;
dm.MyQpayment.SQL.Add('select sdate,stime,pcid,billno,c.customer_name,s.customerid,s.total,s.amount_paid,s.balance');
dm.MyQpayment.SQL.Add(',s.payment_type,s.payment_status,s.delivery from sales_order s left join customer_details c on s.customerid=c.customerid where s.payment_status=''complete'' and s.sdate>="'+startdate+'" and s.sdate<="'+enddate+'" ');
dm.MyQpayment.Active :=true;

I want to dispaly BILL NO and Machine id as BILL NO and the values should be 2_1, if Machine id is 2 and BILL NO is 1. Any idea how to do that?

EDIT1

select CAST(pcid AS CHAR) + "_" + CAST(billno AS CHAR) AS MachineAndBillNo
FROM tt.payment_details ;

this query gives me result as follows

在此处输入图片说明

where it gives machineandbillno=billno+pcid

I do not know the specific MySQL syntax requirements, but you have to concatenate those two fields together:

SELECT 
  sdate, 
  stime, 
  CONCAT(CAST(pcid AS CHAR), '_', CAST(billno AS CHAR)) AS MachineAndBillNo,
  c.customer_name,
  ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM