Q:
在SELECT COUNT(*)時都無法正確取得數量...
故猜測是多了空白...
A:
某A在插入CustomerOrderNo時, 右邊多了N個空白...
Solution Code:
SELECT a.CustomerOrderNo,a.CustomerOrderDate,a.CustomerID,a.CompanyName,(SELECT count(*) FROM [tblT出貨統計資料表] WHERE CustomerOrderNo = replace(a.CustomerOrderNo,' ','')) as Qty
FROM [tblT訂單統計資料表] as a LEFT JOIN [tblODeliveryOrder] as b on a.CustomerOrderNo = b.CustomerOrderNo WHERE b.DeliveryOrderNo = 'PO201210030';
參考:
去除MS SQL欄位中空白
sql字串去除左右空白字元
SQL Trim 函數
沒有留言:
張貼留言