February 4, 2008 at 3:57 am
Hello
This table arranges me to a year's holidays (every sunday and some holidays manually arranged by myself). I wish to access holidays with a query, but what query? If you can post the requird codes, I'd be most thankful. Regards.
create table WorkCalendar
(
dt smalldatetime Primary Key Clustered,
isWeekDay as convert(bit, case when datepart(dw, dt) in (1) then 0 else 1 end),
isWorkDay bit default 1
)
GO
declare @dt smalldatetime;
set @dt = '20080101';
while @dt <= '20081231'
begin
insert WorkCalendar(dt) select @dt;
end
update WorkCalendar
set isWorkDay = 0 where isWeekDay = 0;
--enter some holidays
update WorkCalendar
Set isWorkDay = 0 where isWorkDay = 1
and dt in
(
'20080101',
'20080423',
'20080519'
)
February 4, 2008 at 4:04 am
Could you give the expected output please?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 4, 2008 at 5:24 am
I wish to arrange holidays from my asp 2.0 website. I want to do this; a query that returns me to the all holidays in a year, and if a holiday's next day is a holiday again, then query adds one more day's time to the my site's remaining time calculator. I guess a select query can help me, but I confused :crazy:. Thanks.
February 4, 2008 at 5:48 am
With the table structure you've given, there's no way to tell 100% which days are holidays. It's easy to tell which days are not work days (SELECT dt FROM Calender WHERE isWorkDay = 0)
It's also easy to tell which days are not weekdays (SELECT dt FROM Calender WHERE isWeekDay = 0)
Most holidays can be returned by the query (SELECT dt FROM Calender WHERE isWorkDay = 0 AND isWeekDay = 1), however, that won't pick up holidays that fall on days that are not week days
What do you mean by "site's remaining time calender"?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 4, 2008 at 6:08 am
Very thanks, GilaMonster.
In my website, I used a remaining time calculator that calculates the shipment's remaining time, like this amazon.com examples:
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
Want it delivered Tuesday, February 5? Order it in the next 10 hours and 34 minutes, and choose One-Day Shipping at checkout.
-------------------------------------------------------------------------------------------------
I wish to this time calculator adds one more day's time to the remaining time if next day is a holiday again.
February 4, 2008 at 6:22 am
Could you post the code that you're using for the time calculation please. Along with any tables that it uses, sample data and expected output.
See http://www.sqlservercentral.com/articles/Best+Practices/61537/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 4, 2008 at 6:32 am
I write this code and I used Ajax for dynamic time view. They're C# codes, so... sorry :blush:
protected void Button1_Click(object sender, EventArgs e)
{
Timer1.Enabled = true;
DateTime sonTarih = DateTime.Today.AddDays(1).AddHours(13);
TimeSpan aradakiFark = sonTarih - DateTime.Now;
StringBuilder sb = new StringBuilder();
sb.Append("Remaining time is ");
if (aradakiFark.Days > 0)
{
sb.Append(aradakiFark.Days.ToString());
sb.Append(" days ");
}
if (aradakiFark.Hours > 0)
{
sb.Append(aradakiFark.Hours.ToString());
sb.Append(" hours ");
}
if (aradakiFark.Minutes > 0)
{
sb.Append(aradakiFark.Minutes.ToString());
sb.Append(" minutes");
}
lblSure.Text = sb.ToString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
DateTime sonTarih = DateTime.Today.AddDays(1).AddHours(13);
TimeSpan aradakiFark = sonTarih - DateTime.Now;
StringBuilder sb = new StringBuilder();
sb.Append("Remaining time is ");
if (aradakiFark.Days > 0)
{
sb.Append(aradakiFark.Days.ToString());
sb.Append(" days ");
}
if (aradakiFark.Hours > 0)
{
sb.Append(aradakiFark.Hours.ToString());
sb.Append(" hours ");
}
if (aradakiFark.Minutes > 0)
{
sb.Append(aradakiFark.Minutes.ToString());
sb.Append(" minutes");
}
lblSure.Text = sb.ToString();
}
}
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply