原始sql语句及效果如下:

string sq = @"select gx_plan.id,fk_sec.factory as 本厂编号, `order` as 序号,gx_plan.TotalOrder as 总工序数,note as 备注 from fk_sec,gx_plan
                where (date='" + date + "' or '" + date + "'='') and (fk_sec.AorS='" + machine + "'or '" + machine + @"'='') and (gx_plan.machinetype='" + m + "'or '" + m + @"'='') and(fk_sec.id = gx_plan.fkid) order by beforesplitid desc ";

字段拼接后的语句及其效果:

string sq = @"select gx_plan.id,fk_sec.factory as 本厂编号, concat_ws('/', `order`, gx_plan.TotalOrder) as `序号/总工序数`,note as 备注 from fk_sec,gx_plan
                where (date='" + date + "' or '" + date + "'='') and (fk_sec.AorS='" + machine + "'or '" + machine + @"'='') and (gx_plan.machinetype='" + m + "'or '" + m + @"'='') and(fk_sec.id = gx_plan.fkid) order by beforesplitid desc ";


注意:在sql语句中 ~号 和 ‘号 的区别

更多推荐

SQL语句中字段的拼接