0
我有存儲過程,裏面我有選擇語句,插入和更新,但在我的select語句中,我想將結果存儲在變量中,以便稍後可以訪問它在我的更新聲明中。如何將結果首先存儲在變量中?這是我的選擇語句:如何將sql結果存儲到sql server 2008中的變量
SELECT
REV1 = COUNT(CASE WHEN QTR = 1 AND MAIN_SAT =1 AND ACTIVE_FLAG = 1 THEN 1 END),
REV2= COUNT(CASE WHEN QTR = 1 AND MAIN_EKL =1 AND ACTIVE_FLAG = 1 THEN 1 END),
REV3= COUNT(CASE WHEN QTR = 1 AND MAIN_LAM =1 AND ACTIVE_FLAG = 1 THEN 1 END),
REV4= COUNT(CASE WHEN QTR = 1 AND MAIN_JAC =1 AND ACTIVE_FLAG = 1 THEN 1 END)
FROM MyTable
這個SELECT語句的結果是這樣的:
REV1 REV2 REV3 REV4
12 45 87 54