.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

Creating temp table using stored procedure

Posted By: Nagababu     Posted Date: November 22, 2010    Points:2   Category :Sql Server
Hi All,

I need a dataset dynamically with dynamic columns in my SSRS report.
I am passing table dynamically.How to create a temp table.

Please see the below SP .i am getting invalid object name '#temp'.

ALTER PROCEDURE [xyz]
@tablename Varchar(50)
AS
declare @txtsql varchar(8000)
BEGIN

SET NOCOUNT ON;

set @txtsql ='select * from ' + @tablename

INSERT #temp exec(@txtsql)

select * from #temp
drop table #temp

END


Thanks,

Responses
Author: Sajid P K             
Posted Date: November 22, 2010     Points: 5   

Nagababu,

Where you are creating temp table ?

If it outside , Use Global temp table.



Regards,
sajid P K

Author: Maverick             
Posted Date: February 28, 2011     Points: 20   

Hello,

Use #temp for local temporary table
and use ##temp for global temporary table.

Eg:
create table #temp--for local table within an sp
create table ##temp--for global table

Hope it helps

Thanks,
Maverick


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend