Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Reslving EXECUTE Statement .. URGENT !!!!

Author  Topic 

aravindt77
Posting Yak Master

120 Posts

Posted - 2007-12-24 : 00:59:42


Hi All,


The statement which i run is as follows :_


--------------------

DECLARE @sql NVARCHAR(1000)

SET @sql='SELECT 1 AS Col1 INTO #Tabl1'
EXECUTE (@SQL)
SELECT * FROM #Tabl1

---------------------

The output which I got is as folllows :-

-----------------------
(1 row(s) affected)
Msg 208, Level 16, State 0, Line 5
Invalid object name '#tabl1'.


-----------------------

Can anyone help me in resolving this situation !!!!!

Thanks & Regards

Aravind

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-24 : 02:02:38
Why do you need dynamic sql?

SELECT 1 AS Col1 INTO #Tabl1
SELECT * FROM #Tabl1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

aravindt77
Posting Yak Master

120 Posts

Posted - 2007-12-24 : 05:43:25
quote:
Originally posted by madhivanan

Why do you need dynamic sql?

SELECT 1 AS Col1 INTO #Tabl1
SELECT * FROM #Tabl1

Madhivanan

Failing to plan is Planning to fail





I have use these statments inside a SP which s implemented to arrive a dynamic search functionality ..so that we cant predict the columns at desing time.. Hope u get me
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-24 : 05:48:22
You can't refer local temp table created inside an EXEC statement. Only other way is to use global temp table (##tabl1).

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-24 : 07:14:13
quote:
Originally posted by aravindt77

quote:
Originally posted by madhivanan

Why do you need dynamic sql?

SELECT 1 AS Col1 INTO #Tabl1
SELECT * FROM #Tabl1

Madhivanan

Failing to plan is Planning to fail





I have use these statments inside a SP which s implemented to arrive a dynamic search functionality ..so that we cant predict the columns at desing time.. Hope u get me


Refer this
http://www.sommarskog.se/dyn-search.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -