M
M
Mikhail2018-03-04 19:36:47
MySQL
Mikhail, 2018-03-04 19:36:47

How to store multiple values ​​in a variable?

How can you store multiple values ​​in a variable?

DECLARE @data string[]
SET @data = SELECT text FROM table;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2018-03-04
@mak_ufo

How to store multiple values ​​in a variable?
For MS SQL, you can use list functions. STRING_SPLIT (Transact-SQL) and STRING_AGG (Transact-SQL) .
Список ролей дополняется другим списком без повторов.
DECLARE @Role TABLE(Role VARCHAR(100))
INSERT INTO @Role SELECT TRIM( value ) FROM STRING_SPLIT( @RLR, ',' )
INSERT INTO @Role SELECT TRIM( value ) FROM STRING_SPLIT( @ROL, ',' ) 
                                  WHERE TRIM( value ) NOT IN ( SELECT [Role] FROM @Role )
DELETE @Role WHERE (TRIM( [Role] ) = '')
SELECT @RLR = STRING_AGG ( [Role], ', ' ) FROM @Role

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question