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)
 selecting smallDateTime from datetime

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-04-27 : 05:57:30

Is this ever done? Can it be done?

Basically I store a regular datetime(8) column, but my app only needs the smallDateTime(4) for this one particular query.

Never seen or heard of this, maybe it would be slower..
It's just something that popped into my head, and wondering if anyone knows? :)

Thanks!
mike123

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-27 : 06:12:02
You can alter the column to a SMALLDATETIME if you have no need for seconds and milleseconds.
One large difference is that SMALLDATETIME only handles dates up to June 2079, whereas DATETIME handle dates to December 9999.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-04-27 : 06:17:03
Hey Peso,

I'm not quite yet ready to ALTER it, as a different query needs to use the full data. I have 2 seperate queries, with diff goals.

I just thought it would be nice to trim it down for this 1 query and bring back only 4 bytes on the column since I am only using 4 bytes. No biggie tho.

Thanks once again!!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-27 : 06:20:44
Meanwhile you can create a calculated column

ALTER TABLE Table ADD NewCol AS CAST(OldCol AS SMALLDATETIME)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-04-27 : 06:33:23
Wow very interesting, so this column would also be stored on my table

As I understand it, it will reduce bandwidth on selecting queries from my db server, however it will make my tables grow a little larger.

tough decision for me to make, I'll do some performance testing!

thx!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-27 : 06:40:18
No, it is not "stored" in the table. It is calculated per need basis.
However, with SQL Server 2005, you can make the new column PERSISTED.
Read all about it on Books Online.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -