x

how can we use "Select into" statement with a newly declared table(Stored procedures)

I have declared a temp table @table in procedure and while using the "select into" statement with the temp table getting an error. Is there any way to solve this problem?

DECLARE @table TABLE ([name] varchar(50))

SELECT emp_name INTO @table FROM tbl_Employeemaster

Thanks in Advance

more ▼

asked Nov 20, 2009 at 07:18 AM in Default

Binoy gravatar image

Binoy
37 3 3 3

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You can't do a select into a table variable or an existing table (not even a temporary one) You need to do:

insert into (x, y) SELECT t.x,t.y FROM Table1 AS t 
more ▼

answered Nov 20, 2009 at 07:20 AM

Håkan Winther gravatar image

Håkan Winther
15.6k 34 37 48

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x984
x407

asked: Nov 20, 2009 at 07:18 AM

Seen: 2518 times

Last Updated: Nov 20, 2009 at 11:06 AM