TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
madhu goud
NA
36
14.3k
How to create date column automatically
Jul 29 2015 1:58 AM
This is my code sir
create table demotable
(
Id int primary key identity(1,1),
Name varchar(50),
StartDate date,
EndDate date
)
declare @command nvarchar(max)
declare @dates int, @StartDate datetime, @EndDate datetime
---Here, we assume that,
Select @StartDate = convert(datetime, '1/7/2015'), @endDate = convert(datetime,'1/10/2015')
select @dates = datediff (dd,@StartDate ,@Enddate)
While (@dates >0) begin
set @command = 'alter table demotable add [1/7/2015' + cast(@dates as nvarchar(max)) + '] datetime'
exec sp_executesql @command
select @dates = @dates - 1
end
when i execute this am getting the output is
Id Name StartDate EndDate 1/7/20153 1/7/20152 1/7/20151
but i want date columns like 1/7/2015 1/8/2015 1/9/2015
I want to increase date columns using start date and end date
Reply
Answers (
1
)
Populate textbox with dynamic uploaded word file
How to WebMethod Export PDF File?