Search code examples
parallel-data-warehouse

SQL PDW set multiple variables in SELECT


I am working in SQL Parallel Data Warehouse / APS. I am trying to set the values of multiple variables in a single SELECT statement. My code is:

DECLARE
    @var1 int
    ,@var2 int
;
SELECT
    @var1 = col1
    ,@var2 = col2
FROM
    A
;

PDW is throwing the following error:

Parse error ... Incorrect syntax near '='

Is this not valid syntax on PDW? If not, how do I resolve?


Solution

  • Yes there is a restriction on how you assign variable values. Try this instead:

    DECLARE
        @var1 int
        ,@var2 int
    ;
    SET @var1 = (SELECT col1 FROM A);
    SET @var2 = (SELECT col2 FROM A);