[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

possible to determine weekday with Tsql?

rich

3/21/2007 7:10:00 PM

Greetings,

I need to pull some rows where the date column does not fall on a weekend.
I was experimenting with the Day function, but that only give me the day of
the month. How can filter out weekend dates?

Thanks,
Rich
4 Answers

rich

3/21/2007 7:13:00 PM

0

I think I figured this out

SELECT datename(week,'1/10/04')


"Rich" wrote:

> Greetings,
>
> I need to pull some rows where the date column does not fall on a weekend.
> I was experimenting with the Day function, but that only give me the day of
> the month. How can filter out weekend dates?
>
> Thanks,
> Rich

Aaron [SQL Server MVP]

3/21/2007 7:21:00 PM

0

>I think I figured this out
>
> SELECT datename(week,'1/10/04')

That's not weekday, that returns 2 because it is the second week of 2004
(note: according to SQL Server, not necessarily the same as ISO).

I think you mean DATEPART(WEEKDAY, ...)

Also you should try to avoid ambiguous date formats. If you meant January
10th, then say so.

SELECT DATEPART(WEEKDAY, '20040110');

If you want to return Saturday instead of 7, then:

SELECT DATENAME(WEEKDAY, '20040110');


rich

3/21/2007 7:39:00 PM

0

Thanks very much for this correction. Now it makes sense.

One more question - I noticed that a lot of code statemetns that people
share end with a semicolon. Is that semicolon typed by you or is there a
tool you are using that puts the semicolon at the end of the statement? If
it is a tool, is it a tool that comes with sql server? or is just the
scripting tool?


"Aaron Bertrand [SQL Server MVP]" wrote:

> >I think I figured this out
> >
> > SELECT datename(week,'1/10/04')
>
> That's not weekday, that returns 2 because it is the second week of 2004
> (note: according to SQL Server, not necessarily the same as ISO).
>
> I think you mean DATEPART(WEEKDAY, ...)
>
> Also you should try to avoid ambiguous date formats. If you meant January
> 10th, then say so.
>
> SELECT DATEPART(WEEKDAY, '20040110');
>
> If you want to return Saturday instead of 7, then:
>
> SELECT DATENAME(WEEKDAY, '20040110');
>
>
>

Aaron [SQL Server MVP]

3/21/2007 7:41:00 PM

0

> One more question - I noticed that a lot of code statemetns that people
> share end with a semicolon.

It has always been there as a line terminator... it is optional but
recommended.

For me it's a forced habit now. Since new extensions to the T-SQL language
(e.g. CTEs) require it, I have quickly become quite religious about always
including it.
A