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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding columns in code

Author  Topic 

im1dermike
Posting Yak Master

222 Posts

Posted - 2009-05-05 : 10:11:40
I've written a stored procedure where I'm trying to loop through dates from a certain start date to the current date and add values to a table for each date. What I'd like to do is add a column for each date. The problem is that the syntax doesn't like passing a nvarchar.

ALTER TABLE temp ADD @date_string nvarchar(50)

It wants a non-string, but I don't know how to get it in the right format.

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-05-05 : 10:25:47
this design doesn't look right to me. Regardless, use dynamic sql for this.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-05 : 10:27:47
before you going into that . . why are you adding a column for each date ? what if you have 1000 dates ? are you going to add 1000 columns to your table ? that doesn't sounds right at all.




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2009-05-05 : 11:24:03
Yeah, I just realized it would be much better to transpose my original plan. Dates will now be rows and the columns stay static. :)
Go to Top of Page
   

- Advertisement -