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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-08-22 : 06:59:38
|
| andrew writes "Andrew Krenitz writes "I have the created the following:CREATE TABLE #crosstable (State char(2),LOCNCODE char(11),CUSTCLAS char(15),CPRCSTNM char(15),CUSTNMBR char(15),totals numeric(19,5))I want to add a column to this table:declare @appendString Nvarchar(4000)set @appendString = 'ALTER TABLE #crosstable ADD test varchar(10)'EXECUTE sp_executesql @appendStringThis will not add the column.Please let me know what corections I need to make.ThanksAndy"" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-22 : 07:08:08
|
| Altering the table dynamically is not recommendedWhy do you want to do this?Refer this more on Dynamic SQLhttp://www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
mpetanovitch
Yak Posting Veteran
52 Posts |
Posted - 2005-08-22 : 14:00:17
|
| agreed, dynamic sql in my opinion, is bad practice in almost every aspect. However I'm sure some disagree. I tend to stay away from it. Now, from your query, the reason why its not working is because your local table variable is not in scope to you dynamic sql execution. Try creating a global table ##. Mike Petanovitch |
 |
|
|
|
|
|