|
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
[Back to original message]
|