473,836 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Partition Scheme using a function

I can't seem to find a way to do the following:

create table part_table (
col1 int,
col2 datetime
) on psX (datename(week, col2))

I want to partition based on the week number of a date field.

So if I enter in data like the following in my part_table:

(1, 1/1/2007) should go into partition 1 for week #1
(52, 12/21/2007) should go into partition 52 for week #52 of the year

I tried adding in a computed column, but it says its nondeterministi c.

Feb 20 '07 #1
4 6094
(ea****@cdc.gov ) writes:
I can't seem to find a way to do the following:

create table part_table (
col1 int,
col2 datetime
) on psX (datename(week, col2))

I want to partition based on the week number of a date field.

So if I enter in data like the following in my part_table:

(1, 1/1/2007) should go into partition 1 for week #1
(52, 12/21/2007) should go into partition 52 for week #52 of the year

I tried adding in a computed column, but it says its nondeterministi c.
You are out of luck, I'm afraid. datename() is listed as entirely
undeterministic in Books Online. The normal choice would be datepart(),
which Books Online says is deterministic - with two exceptions of one
being the week number. This example shows why:

set datefirst 7
go
select datepart(week, '20070218') -- 8
go
set datefirst 1
go
select datepart(week, '20070218') -- 7
go
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 20 '07 #2
Ok, so I tried this:

create table part_table (
col1 int,
col2 datetime
) on psX ((datepart(dayo fyear,col2)/7)+1)

and I got "Incorrect syntax near '('. "

select ((datepart(dayo fyear,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)

Feb 26 '07 #3
(ea****@cdc.gov ) writes:
Ok, so I tried this:

create table part_table (
col1 int,
col2 datetime
) on psX ((datepart(dayo fyear,col2)/7)+1)

and I got "Incorrect syntax near '('. "

select ((datepart(dayo fyear,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(dayofy ear, 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, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Feb 26 '07 #4
Yep - that's exactly what I ended up doing....shame to have to add an
extra column (overhead) to the table to do something which should be
so straightforward .
Thanks for your time!
Feb 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
34352
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
41
3567
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of pairs, each pair indicates the sameness of the two indexes. Returns a partitioned list of same indexes.
10
2289
by: Xah Lee | last post by:
another functional exercise with lists. Here's the perl documentation. I'll post a perl and the translated python version in 48 hours. =pod parti(aList, equalFunc) given a list aList of n elements, we want to return a list that is a
1
1504
by: Robby Findler | last post by:
Dear all, I'm writing to let you know about the upcoming Scheme and Functional Programming workshop -- specifically that the submission deadline is June 9, about 2 months from now. The workshop will be held Portland Oregon on September 17, the day before ICFP. We look forward you your submissions!
5
5953
by: sameer_deshpande | last post by:
Hi, I need to create a partition table but the column on which I need to create a partition may not have any logical ranges. So while creating or defining partition function I can not use any range. like CREATE PARTITION FUNCTION my_part_func (NUMERIC(7)) AS RANGE LEFT FOR VALUES (1,100,1000);
2
4803
by: eavery | last post by:
Does anyone know of any documentation on the performance of partition merge/split? Does the merge or split of a partition cause any locking on the partitioned table? If you were merging or splitting a large volume of data rebalancing your partitioned table would you potentially lock users out?
8
17343
ADezii
by: ADezii | last post by:
The inspiration for this Tip was an initial reply by one of our resident Experts to a specific Post. In this Post, the User wanted to know how he could calculate the total number of test results (Satisfactory/Unsatisfactory) for specific age group intervals such as: 20-24, 25-29, etc. The use of the Partition Function was suggested, I followed up with a reply of my own, and it seemed as though some interest was generated in this little know...
0
3792
debasisdas
by: debasisdas | last post by:
SAMPLE CODE TO CREATE SUB PARTITIONS ======================================= RANGE-HASH-9i ------------------------- CREATE TABLE SUBPART ( ID NUMBER(10) PRIMARY KEY, NAME VARCHAR2(20) )
0
3431
debasisdas
by: debasisdas | last post by:
USING PARTITION =================== PARTITION BY RANGE-as per Oracle 8 -------------------------------------- CREATE TABLE RANGEPART ( ID NUMBER(2) PRIMARY KEY, NAME VARCHAR2(20) )
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10551
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10595
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4458
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.