Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team,

Please help me in creating SQL Table with date as column header. Like shown below.

Sno Name 1-06-2013 2-06-2013 3-06-2013 and so on. for entire month.

Thanks in advance
Posted
Comments
chaau 5-Jun-13 21:52pm    
Are you sure this is what you want. It is a very bad design. You will be better off if you put all the dates in a column and have a value associated with the date put in another column. You can always run PIVOT queries against the table to achieve the result in the desired format
_Damian S_ 5-Jun-13 22:37pm    
You should put this as a solution so I can award you some points. ;-)
chaau 5-Jun-13 22:41pm    
That is fine. (whispering) The true solution would be to tell the OP about the square brackets
Member 9989624 8-Jun-13 1:06am    
awarding points for wrong answer is not a good thing.
Member 9989624 8-Jun-13 1:05am    
this isn't a bad design.

You may create like this

CREATE TABLE TableName
(
Sno int,
Name varchar(20),
"1-06-2013" datetime,
"2-06-2013" datetime,
"3-06-2013" datetime,
....
)

Happy Coding :)
 
Share this answer
 
Comments
Member 9989624 8-Jun-13 1:04am    
This s a manual way of adding date as field. If i want to retrieve the values of current date how to do it?
Have a look here: http://msdn.microsoft.com/en-us/library/ms174979.aspx[^]

SQL
CREATE TABLE Table1
(
    ID INT IDENTITY(1,1)
    MyDate DATETIME
)


More about Data Types (T-SQL)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900