Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

ALTER TABLE doc_exa ADD @variable?


Sql Svr 2000.  Can I add a column to a table that is the contents of a
variable?

create table doc_exa (id INT)
go
declare @emp_cd varchar(10)
declare testCursor CURSOR for
select top 8 emp_cd from emp where termdate is null and home_store_cd='08'
open testCursor
fetch next from testCursor into @emp_cd
while @@fetch_status=0
begin
alter table doc_exa add @emp_cd
end

expected result
doc_exa
id INT
slsp1 varchar(10)
slsp4 varchar(10)
slsp88 varchar(10)
slsp89 varchar(10)
slsp234 varchar(10)
slsp651 varchar(10)
slsp794 varchar(10)
slsp846 varchar(10)

Seems like a strange requirement to me. However, that ALTER could be done as dynamic SQL. Put the
ALTER TABLE in a variable then to EXEC(@sql).

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi

"Peter" <P@discussions.microsoft.com> wrote in message

news:3CF0D56F-C8A7-4BB3-9A24-B89309AB8BDB@microsoft.com...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc