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

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

Count rull range in CASE

Posted By:      Posted Date: September 30, 2010    Points: 0   Category :Sql Server
Hi All,

I have following query to calculate interval between dates:

SELECT FullDate,
  when (DATEDIFF(D,(select min(FullDate)from dimTime), FullDate) >=0) and
   (DATEDIFF(D,(select min(FullDate)from dimTime), FullDate) )<=6 then 7
       when (DATEDIFF(D,(select min(FullDate)from dimTime), FullDate) >=0) and
   (DATEDIFF(D,(select min(FullDate)from dimTime), FullDate) )<=29 then 30
       when DATEDIFF(D,(

View Complete Post

More Related Resource Links

returning a date with a count of zero if it doesn't exist in the date range?


i have the following query.

SELECT DATEADD(dd,0, DATEDIFF(dd,0,accesseddate)) AS hitdate, COUNT(hitid) AS hitsperday
FROM hits h
ON h.urlid = u.urlid
WHERE (accesseddate BETWEEN DATEADD(d, -6, GETDATE()) AND GETDATE() AND u.userid = @userid)
GROUP BY DATEADD(dd,0, DATEDIFF(dd,0,accesseddate))

but if there were no "hits" for a particular date range in the last week i only get the dates returned where there were hits. i need to get all the days returned and where there were no results, i need a zero returned.

hitdate            hitsperday

2010-10-07     2
2010-10-06     58
2010-10-04     1645
2010-10-03     1192 

what i need to return is this:     

hitdate                 hitsperday

2010-10-08     0
2010-10-07     2
2010-10-06     58
2010-10-05     0
2010-10-04     1645
2010-10-03     1192

any suggestions?

thank you very much.

List ALL Dates in Date Range When Selecting Count


Say I have a table called "Visits", and I want to create a query that counts the visits per day. 

The way I would accomplish this would be to create a query as such:

SELECT Count(VisitId) as VisitCount, Convert(varchar(32), VisitDateTime, 101) as VisitDate
FROM Visits
WHERE VisitDateTime BETWEEN '10/1/2010' AND '10/5/2010'
GROUP BY VisitDate

The problem I am trying to overcome is that if there were no visits in a given day, that day does not show in my list.  For example, if there were 3 visits on the 1st, 2 on the 2nd, none on the 3rd, and 5 on the 4th, my result set would look like:

3, 10/1/2010
2, 10/2/2010
4, 10/4/2010

How can I create my query so that I get all days in the date range listed in the result set regardless of whether the VisitCount is zero?


If or Case in a LINQ SQL code, How to Use Count() Request.QueryString("imageidentity")



If i want to get some diffrent data from a DB
and its by using Request.QueryString("SortBy")

What do u use !?
If The Else or Case !?

What i want is that if SortBy in the Url link is NameUP, then its sorts by A, B C and so on
and if NameDown then the other way.

Im using this LINQ code.

    Public Sub linqdb()

        Dim DBconn As New GetProductListDataContext()
        Dim Q = _
        From p In DBconn.GetTable(Of Product)() _
        Where p.IsEnabled = "1" _
             Order By p.PName Descending _
        Select p
        Dim L = Q.ToList
        MyRep.DataSource = Q
        PValue.Text = L.Count().ToString()

    End Sub

 How do i also get this code to Count the outgoing records !?
I cant get any number from PValue.Text = L.Count().ToString()
from my CB to my .ASPX site with a <asp:Label ....

Visual Case Tool - UML Tutorial

The Class Diagram

The class diagram is core to object-oriented design. It describes the types of objects in the system and the static relationships between them.

Use Case Diagram

The use case diagram shows the functionality of the system from an outside-in viewpoint.

Actors (stick men) are anything outside the system that interacts with the system.

ListViewControl - how to group items by their value, for eg. date range



I have a table containing courses, columns are 

Name - "Yoga Classes"

DateStart - "2/23/2010"

DateEnd - "2/24/2010"

I am using ListView Control to bind it, is there a way to display them and group them by Month? 

for eg.


Piano Class (10th Jan 2010 - 11th Jan 2010)
Guitar Class (10th Jan 2010 - 11th Jan 2010)


Yoga Class (15th Feb 2010 - 16th Feb 2010)

Thanks for help.

Print row count on Label



I have an SP that simply performs a COUNT(*) from a table. I'm am trying to print that number in an ASP Label. It works in Query analyzer but I cant wrap my head around how to display it in a label. Any guidance much appreciated. 

Thank you. 

Count words in the ascx file



I have 163 .resx files. I want to count the words in these files, because my want to translate the sentences (my task is the localisation).

Now I'm opening each file in Ms Visual Studio and I count words manually. How can I count words in all files? And the second question: can I use a program what grab strings from .resx into an editor where I can translate them and save bacn into .resx files? Or must open the files one by one and edit the text fields manually?

Thanks for helping, unfortunately I'm not a programmer.

System.DateTime.AddDays: Value to add was out of range.


I'm getting the following error:

[ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value]
   System.DateTime.Add(Double value, Int32 scale) +7657639
   System.DateTime.AddDays(Double value) +19

The line from which this error originates has the following code:

expires = Now.AddDays(30)

It occurs irregularly and irreproducably. The server date/time is correct and set to GMT. I've heard that it could be some curiosity to do with timezones, but that is speculative.

It seems that we're some time from the year 10,000 yet, so I can't understand why adding thirty days to the current time could cause this! Any ideas? Culture settings perhaps?

How to display a count of search results with keywords in a label?


Sorry for a basic post here; I am very new to VB!

I am currently building a search page, which includes a textbox and two drop-down lists, a search button, and a datagrid. If results are found and displayed, I would like a label to display:

(e.g.) "24 results found for 'blue sky clouds' "

...where the integer represents the results count, and the keywords and/or drop-down list selections are included in the string.

If no results are found I would like the label to display:

(e.g.) "No results were found that match your selection. Please try again"

I would also like the label to be invisible until a search occurs.

Thanks in advance!



Hello, i need help changing the following code into a switch...case statementUndecided

<script runat="server">
void Page_Load()
    if (Page.IsPostBack)
    public String toSring()
    int intcomputerChoice=1;
       if (Page.IsPostBack)

Editor's Note: In Case You Hadn't Noticed .


Find out what's new for MSDN Magazine, including a print redesign and the introduction of virtual labs on our web site so you can experiment with our code.

Howard Dierking

MSDN Magazine June 2008

Editor's Note: Rich Clients Count Too


It's the dead of winter here at the MSDN Magazine offices, and we're having a blast. Temperatures are making their daily struggle to stay above zero. The tempting aroma of chestnuts roasting on an open subway ventilation grate fills the city with a wintry mix of excitement and anticipation.

MSDN Magazine February 2003

.NET Migration Case Study: Using ASP.NET to Build the beta.visualstudio.net Web Site


When the Web site used to collect customer feedback about the Visual Studio .NET beta needed an update, the Visual Studio team saw a good opportunity to implement, deploy, and showcase a real-world site using .NET technologies. This article covers the migration of the Web site, beta.visualstudio.net, from components written in Visual Basic 6.0 and ASP hosted on Microsoft Internet Information Services (IIS) 5.0 to ASP.NET and the .NET Framework. The choices of technologies to be incorporated, along with issues such as validation, security, and authentication, are all discussed. Both existing components and the new components written in JScript and ASP.NET that were used to migrate the site are also explained.

Jay Schmelzer

MSDN Magazine September 2001

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