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 |
|
tocroi72
Yak Posting Veteran
89 Posts |
Posted - 2004-09-20 : 10:23:03
|
| Hi allI have this script:Declare @Var int, @sql nvarchar(2000),@column nvarchar(100)Set @var = 1While @Var <= 32begin set @column = 'day' + convert(varchar,@var) SET @sql = 'INSERT INTO Master SELECT YandMColumn,' + convert(varchar,@var) + ',' + @Column + ' From High' Execute @sql set @var = @var + 1--print @sqlEndWHen i run the script, it returns me this erro message belowCould not find stored procedure 'INSERT INTO Master SELECT YearColumn,1,day1 From High'.I have a table of data for a year like thisYandMColumn|Day1|day2|day3.....Day31|1996/01 12 32 431996/02 14 31 56and I want to create a table look like thisYandMColumn|Day|Amount1996/01 1 121996/01 2 321996/01 3 431996/02 1 141996/02 2 311996/02 3 56 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-09-20 : 10:47:51
|
first try executing it like:Exec(@sql)instead ofExecute @sqlBut beyond that, it seems like you may not be approaching this right... you may want to do subqueries or something more set-based.ie:Insert Into masterSelectYandMColumn,Day1 = (Select count(*) From High Where day(someDate)=1),Day2 = (Select count(*) From High Where day(someDate)=2),Day3 = (Select count(*) From High Where day(someDate)=3),...From (Select distinct YandMColumn From High) A Corey |
 |
|
|
tocroi72
Yak Posting Veteran
89 Posts |
Posted - 2004-09-20 : 11:05:50
|
| Thanks for the syntax help : Exec(@sql), i put the bracket in and it works.I think my logic is correct.Hannah |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-09-20 : 11:06:54
|
Well as long as it works for you Corey |
 |
|
|
|
|
|
|
|