.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

longest consecutive days in sql?

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :Sql Server

I have a table like this:

CREATE TABLE [dbo].[Logs](

    [logDate] [datetime] NULL,
    [logType] [int] NULL,
    [logCacher] [varchar](128) NULL,


Some sample data:


INSERT INTO Logs VALUES ( '21/11/2007 00:00', 1, 'geocacher1' )
INSERT INTO Logs VALUES ( '21/11/2007 00:00', 1, 'geocacher1' )
INSERT INTO Logs VALUES ( '22/11/2007 00:00', 1, 'geocacher1' )
INSERT INTO Logs VALUES ( '22/11/2007 00:00', 1, 'geocacher1' )
INSERT INTO Logs VALUES ( '23/11/2007 00:00', 1, 'geocacher1' )

INSERT INTO Logs VALUES ( '23/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '24/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '25/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '25/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '27/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '29/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '29/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '30/11/2007 00:00', 1, 'geocacher2' )
INSERT INTO Logs VALUES ( '30/11/2007 00:00', 1, 'geocacher2' )


View Complete Post

More Related Resource Links

Editor's Note: The Future: A Few Days Away


The past year has been full of uncertainty and change. A year ago, everything seemed to be falling into place. Windows XP was nearing final release. An RC version of the Microsoft . NET Framework was whetting our appetites for the final February release.

MSDN Magazine November 2002

Only 12 days left in the Code Contest!


We are having a fun coding contest to find the best solution to a fairly trivial coding problem.  Come along and show off your skills . you might just win a totally awesome Gyroscope Powerball!

Participate in the Code Contest!

Force password expiration after x days


Using C# and sqlmembershipprovider forms authentication, is there a way to force user password to expire and need to be reset after x number of days?

So if a user launches the website login.aspx page, when they type their userid, it will check if the password is expired and direct them to a Resetpassword.aspx page?

Sharepoint access dissabled automatically in every two days

The problem seems to be that our administrators grant access to specific portals / folders and then without warning or any actions from our part the next week access is disabled

Display 'Top Queries Over Previous 30 Days' to users


In the Site Usage Reports, there is a section for 'Top Queries Over Previous 30 Days'. I would like to display this information to users. 

Is there a existing webpart for this? 
Is the data stored in a list that can be used for this purpose?


Steve Clark

How to add days in date using javascript


Hi following is the javascript code which i used for adding days to date

my date is 25/08/2010  and i want to add 8 days to this date  the answer should be 03/09/2010. how it is possible. i tried following code but showing error.



<script type="text/javascript" language="javascript">

function check()
var myDate = new Date();
var vFormat="MM/dd/yyyy";
var vDay                = addZero(myDate.getDate()); 
var vMonth            = addZero(myDate.getMonth()+1); 
var vYearLong         = addZero(myDate.getFullYear()); 
var vYearShort        = addZero(myDate.getFullYear().toString().substring(3,4)); 
var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
var vHour             = addZero(myDate.getHours()); 
var vMinute           = addZero(myDate.getMinutes()); 
var vSecond           = addZero(myDate.getSeconds()); 
var myDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
myDateString           = myDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 

function addZero(vNumber){ 
    return ((vNumber < 10) ? "0" : "") + vNumber 


Absence and vacation days webparts calculation



does any1 know if there is a webpart that can calculate an employee's vacation days. and when the employee request some vacation days it show the days that are left.

or is there a tutorial to create such a webpart?


month days in gridview


 Hello all,

I have a challenge of which I can't figure out how to achieve it.

at this moment I have a gridview that can be dynamicly filled with cell's based upon the number of items selected (throug a drop down list) by a user.

the user then can enter some values in the cells to perform a bulk insert.

What I rather want is that the user selects a month, like august, and then  the gridview is filled with the amount of days from that month, so you get 31 cells in the gridview. second all the first cells should be filled with the daynumber for that day...

I hope the explanation is clear :)


Does anyone know a solution to this?





select records within 30 days of previous records

I have a table with a list of patient id's and there begin date and end dates as follows: ID     begin_date  end_date 1234 10/09/2009 10/16/2009 1234 12/16/2009 12/22/2009 1234 12/28/2009 12/30/2009 1234 01/13/2010 01/19/2010 1234 04/29/2010 05/05/2010 what i need to do is select the records that have an end_date within 30 days of a begin_date. So in the above example, i would need to get the following records: ID     begin_date   end_date 1234 12/28/2009   12/30/2009 1234 01/13/2010   01/19/2010 Because 12/28/2009 is 30 days within 12/22/2009 (previous end_date) and 01/13/2010 is within 30 days of 12/30/2009 (previous end_date) and 12/22/2009 (2nd previous end_date). is there a good way to do this using T-SQL?

The "60 days clean-up syndrome", how to recover?

Hi, Like many others, I woke up just to find that SP job has deleted my WF tasks (and history) from a critical system... The tasks are being displayed in all the reports and are important to understand the flow of a process. Now we must recover the data somehow, we are mostly interested in recovering the WF instance and tasks. We have DB backups. I know we should deal with the Workflow table, from which table does the tasks items come? Any tips? Free tools to recover list items from DB backup?   10x in advanced....

Get last seven days records excluding Weekend days ?

Hi , I'm trying to extract records from table inserted in last seven working days . I'm unable to exclude Sunday and Saturday from this : select * from tb_Name where dt >=DateAdd(dd, DateDiff(dd, 0, Getdate()), 0) and dt<DateAdd(dd, DateDiff(dd, 0, GetDate())-7, 0) Any pointers would greatly  be valued and appreciated . Thanks .Rajkumar Yelugu

Percentage of matching days off among employee's

Hi All,i have Intime and Outtime of each employee for all the days of 1st,2,3,4 week.There will be a off for 1 day or 2 days for each employees.Based on this i need to calculate consisitency days off assignmanet i.e no of matching days off among employees in percentage.If there are 100 emplyees out of 100 employees 50 people may get week off on the same day(for example sunday). I want result in percentage.result like thisConsistency Days of assignment            Across 4 weeks            3 weeks                2weeks                0                                                             2%                                   0%     &

Algorithm for Computing Age in Years, Months and Days?

I am generating a crystal report.net that compute age of a person through formula. of course, there is the birthdate and current date. I am familiar with the datediff function but I want to compute is like: "18 Years, 2 Months and fifteen days old." it should include the leap year. Any Algorithm that I can apply to crystal report formula? Your help is very appreciated.

Count numbers of days (no time table in datasource)

I read the following regarding adding a measure for counting the number of days: The trick is to create new measure group, which will have only one dimension - Time, and a measure with Aggregation Type 'Count' bound to the Day attribute of Time dimension (or any other attribute if we need to count something different from days). The most important setting on this new measure group is to leave IgnoreUnrelatedDimensions=true - this will allow to use this measure across any other dimension in the cube. Howerver, this solution assumes that one has a time dimension based on a table in the datasource. I have a Time dimension that created was by the BIDS wizard that is not in my source database but appearantly invisibly hidden on the AS server without direct access to it. (If I try to add a new measure group (as needed according to the post above) then I can only choose from tables that have nothing to do with time). Can somebody explain how I can do this without a specific timetable in my datasource? Do I need to add a timetable just for this purpose? Can it be stand-alone or do I need to add a relationship with all current tables that have date-columns in them? (I am a finance manager that is building a sales cube based on Navision 3.6, which is already working quite nicely, but still very much a newby)

MDX problem: Return the number of days in a given selection/range

I've had this problem for a couple of days and found some "solutions" online. However, none of them worked. The goal is to calculate Inventory Turnover, but the problem is I can't seem to return the current number of days in the selection. The solution I found was: Count(Descendants([Date].[Date Hierachy], [Date].[Date Hierachy].[Date])) Which returned this: http://www.jandd.be/images/q_return.jpg However, I just want it to return the number of days that are in the selection, so the number of days between (incl) 22/08 and 25/09. This is a screenshot of my datedim, if it helps: http://www.jandd.be/images/q_datedim.jpg I can imagine this could be real simple or some setting that I didn't find on the dimensions, but it would be really appreciated if I could find a solution like this...

Select all articles that have participated in a merge replication in the last n days/weeks

I have a merge replication set up in MS Server 2000. Some of the published articles are not used. I am trying to write a query that will select these articles as well as the time when they have been last used in the replication. I was know that in the distribution database there is a table [MSmerge_history] however I cannot figure out how to join it to MSarticles. Any help will be much appreciated! Regards, Pencho

How i can view last 5 days records in current Month

Suppose i have a tableAppno Receive_Date Send_Date 1 9/3/2010 9/3/2010 2 9/3/2010 null 3 9/4/2010 9/4/2010 4 9/9/2010 9/9/2010 i m trying to run this select * from search where datediff(d,send_Date,getdate()<5
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend