You are here: Re: Partition Scheme using a function « MsSQL Server « IT news, forums, messages
Re: Partition Scheme using a function

Posted by Erland Sommarskog on 02/26/07 22:17

(eavery@cdc.gov) writes:
> Ok, so I tried this:
>
> create table part_table (
> col1 int,
> col2 datetime
> ) on psX ((datepart(dayofyear,col2)/7)+1)
>
> and I got "Incorrect syntax near '('. "
>
> select ((datepart(dayofyear,getdate())/7)+1) will give me the correct
> week of the year that I want. (first week starts on the first day of
> the year this way)

Here is something that completes without errors. I canoot vouch for
that it make much sense, though. I have not looked very much into
partitioned tables myself.


CREATE PARTITION FUNCTION partfun(int) AS
RANGE FOR VALUES ()
go
CREATE PARTITION SCHEME psX AS PARTITION partfun TO ([PRIMARY])
go
create table part_table (
col1 int NOT NULL,
col2 datetime NOT NULL,
weekno AS datepart(dayofyear, col2) / 7 + 1 PERSISTED,
PRIMARY KEY(weekno, col1)
) on psX (weekno)
go
drop table part_table
drop partition scheme psX
go
drop partition function partfun




--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация