Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Using SET how can i store multiple Values?

When I'm trying to assign multiple values (which are extracted from a database)like this

DECLARE @Level4 varchar(255)

SET @Level4 = '[A,B]'

i'm not getting a proper result.


Can any one let me know how to store multiple values to a particular column?

What I have tried:

DECLARE @Level4 varchar(255)

SET @Level4 = '[A,B]'

Where statement :

(acnt.[Level 4] = @MyAccountLevel4) OR (@MyAccountLevel4 IS NULL)
Posted
Updated 16-Jul-20 21:48pm

1 solution

If i understand you well...

You can declare variable type of table:
SQL
DECLARE @tmp TABLE(Column1 As VARCHAR(255))


Then:
SQL
INSERT INTO @tmp (Column1)
SELECT OtherColumn
FROM YourTable
WHERE YetAnotherColumn = 'SomeValue'


To get values from table variable:
SQL
SELECT *
FROM @tmp


For further details, please see: Differences between SQL Server temporary tables and table variables[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900