我已經嘗試了幾種不同的方式,包括IF和CASE語句,但我不能完全看着辦吧......如果U.LastName爲空,我如何讓Customer列忽略空格和逗號?
SELECT U.Login AS Login, U.LastName + ', ' + U.FirstName AS Customer,
cast(cast(IsNull(sum(O.BillAmount), 0) as decimal(19,5)) as float) AS 'Total Billing',
MIN(O.DateOrderCreated) AS 'First Order',
MAX(O.DateOrderCreated) AS 'Last Order'
FROM Orders O
INNER JOIN Store S ON S.StoreID = O.StoreID
INNER JOIN fn_UserStores(@ActiveUserId,12) US ON S.StoreId = US.StoreId
INNER JOIN Users U ON U.UserID = O.UserID
WHERE (O.IsCart = 0) AND (U.StatusID <> 2) AND (O.IsSaveForLater = 0)
GROUP BY U.Login, U.LastName + ', ' + U.FirstName ORDER BY U.LastName + ', ' + U.FirstName
下次會做。謝謝! –
或者你可以編輯:^)。 http://i.stack.imgur.com/sDy36.png –