Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to declare array inside Sql Server Stored Procedure?
    primarykey
    data
    text
    <p>I need to declare 12 decimal variables, corresponding to each month's year, with a cursor I sum values to this variables, then later I Update some sales information.</p> <p>I don't know if sql server have this syntax</p> <pre><code> Declare MonthsSale(1 to 12) as decimal(18,2) </code></pre> <p>This code works Ok. !</p> <pre><code>CREATE PROCEDURE [dbo].[proc_test] AS BEGIN --SET NOCOUNT ON; DECLARE @monthsales TABLE ( monthnr int, amount decimal(18,2) ) -- PUT YOUR OWN CODE HERE -- THIS IS TEST CODE -- 1 REPRESENTS JANUARY, ... INSERT @monthsales (monthnr, amount) VALUES (1, 100) INSERT @monthsales (monthnr, amount) VALUES (1, 100) INSERT @monthsales (monthnr, amount) VALUES (2, 200) INSERT @monthsales (monthnr, amount) VALUES (3, 300) INSERT @monthsales (monthnr, amount) VALUES (4, 400) INSERT @monthsales (monthnr, amount) VALUES (5, 500) INSERT @monthsales (monthnr, amount) VALUES (6, 600) INSERT @monthsales (monthnr, amount) VALUES (7, 700) INSERT @monthsales (monthnr, amount) VALUES (8, 800) INSERT @monthsales (monthnr, amount) VALUES (9, 900) INSERT @monthsales (monthnr, amount) VALUES (10, 1000) INSERT @monthsales (monthnr, amount) VALUES (11, 1100) INSERT @monthsales (monthnr, amount) VALUES (12, 1200) SELECT monthnr, SUM(amount) AS SUM_MONTH_1 FROM @monthsales WHERE monthnr = 1 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_2 FROM @monthsales WHERE monthnr = 2 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_3 FROM @monthsales WHERE monthnr = 3 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_4 FROM @monthsales WHERE monthnr = 4 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_5 FROM @monthsales WHERE monthnr = 5 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_6 FROM @monthsales WHERE monthnr = 6 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_7 FROM @monthsales WHERE monthnr = 7 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_8 FROM @monthsales WHERE monthnr = 8 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_9 FROM @monthsales WHERE monthnr = 9 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_10 FROM @monthsales WHERE monthnr = 10 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_11 FROM @monthsales WHERE monthnr = 11 GROUP BY monthnr SELECT monthnr, SUM(amount) AS SUM_MONTH_12 FROM @monthsales WHERE monthnr = 12 GROUP BY monthnr -- END TEST CODE END </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload