In this SQL Server article I will explain how to write query to get records Exclude weekends data or without weekends data in SQL Server.
SELECT * FROM yourtable WHERE ((DATEPART(dw, yourdatecolumn) + @@DATEFIRST) % 7) NOT IN (0, 1)
|
CrDate
|
DayOfDate
|
2012-11-28 09:00:00.000
|
Wednesday
|
2012-11-29 07:24:11.000
|
Thursday
|
2012-11-30 11:21:43.000
|
Friday
|
2012-12-01 06:32:11.000
|
Saturday
|
2012-12-02 09:55:22.000
|
Sunday
|
2012-12-03 10:30:31.000
|
Monday
|
2012-12-04 01:11:59.000
|
Tuesday
|
SELECT * FROM UserInfo WHERE ((DATEPART(dw, Crdate) + @@DATEFIRST) % 7) NOT IN (0, 1)
|
CrDate
|
DayOfDate
|
2012-11-28 09:00:00.000
|
Wednesday
|
2012-11-29 07:24:11.000
|
Thursday
|
2012-11-30 11:21:43.000
|
Friday
|
2012-12-03 10:30:31.000
|
Monday
|
2012-12-04 01:11:59.000
|
Tuesday
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
5 comments :
Thanks a lot Suresh...
I needed these functionality some 4 months back and since i wasn't able to do it in SQL , i'd to implement these logic from front end...
Wish you'd written this article earlier...
Excellent Query...
Thanks a lot...
I have got one requirement that in my table i'm having with the column names Fname, Lname and mobileNo. For example Fname=abc, Lname=xyz, mobileNo=9012345678. Then the result should be like
string PersonId=abcxyz5678;
From the above string object we can find out one thing that I am combining Fname,Lname,mobileNo together in a string object with the help of query but here I want to take only last four digits of the mobileNo through the query.
Could u plz solve my problem.
Thank you. . .
@Shrinivas...
if you want to get last four digits you need to use substring function for that check below post
http://www.aspdotnet-suresh.com/2012/04/sql-server-substring-function-example.html
it works.....thnku sir