6
Declare @T_variable table(name varchar(200))
SET @T_variable =(SELECT au_lname FROM Testing)

Error Message. Msg 137, Level 16, State 1, Line 2 Must declare the scalar variable "@T_variable".

Note :- select statement result will give multiple rows.

I try to capture the select result in table variable.But i failed. Is there any way to capture the select result to Table variable Dynamically.

Thanks in advance.

2 Answers 2

15

Please try below query instead since you have declared a table variable instead of a datatype variable.

Declare @T_variable table(name varchar(200))
insert into @T_variable 
SELECT au_lname FROM Testing
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

SET @T_variable :=(SELECT au_lname FROM Testing)

Adding a colon may help here.

2 Comments

Is your answer better than the selected answer?
someone may find this useful.@jhhoff02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.