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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to separate Date from Datetime datatype

Author  Topic 

sqlnewbee
Starting Member

4 Posts

Posted - 2007-11-21 : 18:55:07
I want to setup server time dimension in SQL server 2005 Analysis Services. So I need to add a date column in a fact table which will contain only date part and skip time part of dateime datatype.

How can I insert a column in a table which will store only date?

Any suggestion with some syntax will be greatly appreciated as I am pretty new in SQL.

Thanks in advance

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-21 : 18:59:47
http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx

http://weblogs.sqlteam.com/jeffs/archive/2007/10/31/sql-server-2005-date-time-only-data-types.aspx


Those should give you all you need to know and more..




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

sqlnewbee
Starting Member

4 Posts

Posted - 2007-11-22 : 11:55:34
Hello,

Thanks for the reply.

But still it is containing 12 AM time part which is giving me error in Analysis services.

Any idea how to add computed column with datepart function which will add only date part?

Thanks!
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-11-22 : 15:25:02
The datetime data type contains a date and a time. You can zero out the time, which is what you are doing when you get the time as 12:00AM, but you cannot remove the time from a datetime. If you are getting an error because of the time, then the data type you passing that value to is not expecting a datetime. It sounds like it may be expecting a string that contains a formatted date. If that's what you need then you can use the CONVERT function to convert the datetime into a varchar(10) containing only the date.
Go to Top of Page

evilDBA
Posting Yak Master

155 Posts

Posted - 2007-11-22 : 16:38:09
Hm, I remember in alpha or beta of Yukon I've seen types date, time, and gmtdatetime...
It was a long time ago, I am even not sure about it.
Interesting, what was a reason to abandon these data types?
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-11-22 : 17:28:00
Not in sql2k5, they are in sql2k8 finally.
Go to Top of Page

sqlnewbee
Starting Member

4 Posts

Posted - 2007-11-22 : 18:43:51
Best thing I found is to create an UDF and use it to add a computed column.

Thanks!
Go to Top of Page
   

- Advertisement -