0
嘿,我想知道如何將變量設置爲以下查詢字符串的輸出:SQL服務器:從查詢輸出設置變量
SELECT count(*) fees_quantity,
1.5 fees_price,
1.5 * count(*) fees_amount,
round(SUM((CONVERT(int,Points) * .1)),0)) redep_amount,
round(SUM((CONVERT(int,Points) * .1)),0)) + 1.5 * count(*) total_amount
FROM tblHGP HGP,
OrderDetails OD,
tblInvoices i
JOIN tblCS cs ON i.INumber = cs.INumber
JOIN tblECI ac ON i.INumber = ac.INumber
WHERE cs.SoldTo = HGP.ECard
AND issued BETWEEN '2010-09-01' AND '2010-09-30 23:59:59'
AND Country = 'US'
AND HGP.iNumber = OD.orderdetail
我怎麼能這樣做?
DECLARE @FeesQty varchar(3)
DECLARE @FeesTotal varchar(10)
DECLARE @RedepTotal varchar(10)
DECLARE @Total varchar(10)
@FeesQty = fees_quantity
@FeesTotal = fees_amount
@RedepTotal = redep_amount
@Total = total_amount
這怎麼能做到?
謝謝!
大衛
真棒加布裏埃爾!謝謝一堆! :o) – StealthRT 2010-10-22 17:50:02
在SQL中,您應該嘗試「匹配」數據類型。如果生成一個數字(例如從該數(*)),它應該存儲在一個適當類型的變量 - 例如,我會使@FeesQty一個int。讓GUI處理格式問題,因爲它們做得更好。 – 2010-10-22 17:53:06
@菲利普凱利:非常真實! – 2010-10-22 18:31:51