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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 alter n update temptable
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ZaraAnn
Starting Member

2 Posts

Posted - 09/25/2012 :  00:20:41  Show Profile  Reply with Quote
Hi, I am facing with this kind of prob where I could not Alter and update temptable in 1 stored procedure(SP). in 1 SP, i pivot from 2 tables, insert data into temptable, then trying to insert 1 col and update it.

ALTER PROCEDURE [dbo].[uspgetdata]
@dataid nvarchar(50)

--pivot

ALTER TABLE ##TableTemp ADD dataID varchar(50);
UPDATE ##TableTemp SET dataID =@dataid ;

--full join table 1 and ##TableTemp

the error --> Invalid column name 'dataID'.

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 09/25/2012 :  00:45:30  Show Profile  Reply with Quote
dynamic pivoting ?
it is easier this way
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx


KH
Time is always against us

Go to Top of Page

ZaraAnn
Starting Member

2 Posts

Posted - 09/25/2012 :  00:57:12  Show Profile  Reply with Quote
no khtan, actually pivoting done. error occurs when i'm trying to alter that ##TableTemp

my SP
-----

ALTER PROCEDURE [dbo].[uspgetdata]
@dataid nvarchar(50)

BEGIN
--pivoting table Done

--Trying to alter and update ##TableTemp
ALTER TABLE ##TableTemp ADD dataID varchar(50);
UPDATE ##TableTemp SET dataID =@dataid ;


*i'm trying to insert the dataID so that i can proceed with the inner join


--full join table 1 and ##TableTemp
END

thanks khtan, anyway i'll try to modified my SP based on the example page u gave.

Edited by - ZaraAnn on 09/25/2012 01:04:49
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000