Suganth G
Suganth G

Reputation: 5156

how to get the cell value from table and assign to the variable in sql

I need to assign the output of split to the variable, how can do this, i tried this

DECLARE @StartMonth nvarchar(5) = select top 1 Value from dbo.split('jun - may', '-')

Step 1:

select top 1 Value from dbo.split('jun - may', '-')

Output is jun

Step 2:

I need to assign it to the variable @StartMonth

Upvotes: 0

Views: 1606

Answers (3)

aynka2000
aynka2000

Reputation: 11

Do the following

Declare @StartMonth nvarchar(5)

select top 1 @StartMonth = Value from dbo.split('jun - may', '-')

Upvotes: 0

Kiran Hegde
Kiran Hegde

Reputation: 3681

Try this

DECLARE @StartMonth nvarchar(5) 
select top 1 @StartMonth = Value from dbo.split('jun - may', '-')

Upvotes: 1

Wagner DosAnjos
Wagner DosAnjos

Reputation: 6374

Please try the following:

DECLARE @StartMonth nvarchar(5)

select top 1 @StartMonth = Value from dbo.split('jun - may', '-')

Upvotes: 1

Related Questions