.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

Need Help in a query... How to Display Last Record For a Given Month

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

Hi All,

I have a table DBGROWTHTABLE with below structure and data.

USE [ibmdba]


/****** Object: Table [dbo].[DBGROWTHTABLE] Script Date: 10/22/2010 11:54:02 ******/








	[TableEntryID] [int] IDENTITY(1,1) NOT NULL,

	[EntryDate] [smalldatetime] NOT NULL,

	[MachineName] [varchar](100) NULL,

	[InstanceName] [varchar](100) NULL,

	[DBNAME] [varchar](100) NULL,

	[DBsizeMB] [bigint] NULL,

	[unallocMB] [bigint] NULL,

	[reservedMB] [bigint] NULL,

	[dataMB] [bigint] NULL,

	[indexMB] [bigint]  

View Complete Post

More Related Resource Links

Display the Sum of hours and Month Year using sql Query

Hi,  I have,hours(in varchar),Id in table tbl_x ,i need the sum of hours, monthyear(eg. mar 2010)for the last three months.But with two separate queries i am getting these results.but actually i need in the following format   Month/Year      TotalHours-----------------    ----------------Mar 2010            0400Apr 2010             0450-----------------------------------to get month/Year i am using this querySELECT right(convert(varchar, fromdate, 106), 8) from tbl_x where id='11101' for the sum of hours SELECT SUM(CAST(hours AS INT))AS TOTALHRS FROM tbl_x WHERE id='11101'

GridView inline Master/Detail record display

This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time (ya, right) you may want to review the source code.

Need Help in LINQ query for group By with chunks of record


I am assigning and unique id [strShipperIdSequence] on my List on bases of some properties which are grouped together uniquely.
Now what i needed is that my group should be further break down to some maximum amount of chunks.[Let say 10]
that mean's even i am having Same value in 12 records i should get 2 groups[I of 10 items and other of 2 items]

var uniqueGroups = objMdbContentInfoList.GroupBy(p => new
}).Select(g => g.First()).ToList();
foreach (var objUnique in uniqueGroups)
string strShipperIdSequence = APIGlobalMethods.GetShipperRequestID();
foreach (MdbContentInfo obj in objMdbContentInfoList.FindAll(h => (h.CON_ENTRY_POINT == objUnique.CON_ENTRY_POINT &&
h.APPTType == objUnique.APPTType &&

Passing Primary Key to User Control to Display Record Detail


I'm building a user control to display detail information on a parent record. The user control will be displayed via an Ajax Modal Popup. The user control works and is displayed when expected. The problem that I'm having is that I'm not able to pass in the primary key for the parent. The control is displayed via the _ItemCommand event of a Repeater. In the markup for the user control, I explicity set the ContactId to 0 to avoid an error when the control loads (its still underdevelopment, eventually that I'll check if the value is valid).

I was assuming that I could change the property in the _ItemCommand event, but obviously its not working.

In the Page_Load event this code successfully sets the ContactId property of the control. The _ItemCommand event appears to set the value. However when I set a test label on the user control to the Me.ContactId, its showing '0' as if it was never passed in.

        UserControlContactDetail.ContactId = "1462"
        test.Text = UserControlContactDetail.ContactId

    Protected Sub RepeaterDirectory_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles RepeaterDirectory.ItemCommand

Protected Sub RepeaterDirectory_ItemCommand(By

Display Employee Record


I have employee table and qualification table

Each employee has multiple qualifications

Now what i want to display is employees basic information like name, identity card, designation etc..

With all the qualification he/she has

please let me know how can i do that

Following is situation which i dnt want


Identity card :123


Qualification one


Identity card :123


Qualification two

Display Inserted Record After Insert Using A FormView

How do I display a record in a FormView once the record has been inserted? I'm able to get the Identity of the new record without anyproblems, but I can't figure out how I should code the _ItemCreated event. Protected Sub FormViewMessageDetail_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) 'Refresh the list to show the new record RepeaterMessages.DataBind() 'Set the .SelectCommand to Select the New Record SqlDataSourceMessageDetail.SelectCommand = "SELECT * FROM Messages WHERE [Id] = " & NewId FormViewMessage.DataBind() FormViewMessage.ChangeMode(FormViewMode.Edit) test.Text = NewId.ToString End Sub Protected Sub SQLDataSourceMessageDetail_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) NewId = e.Command.Parameters("@NewId").Value End Sub

Calender control to display dates of one month only

How to make calender control to display dates of one month only like for month of June it shows 25 to 31 of May and 1 to 5 of July. like this-   25 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5   I want it to be displayed like this- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30   Any ideas

how do I search record from database and display that in Datagridview.

hi,I am working in windows application.I wanted to search record while entering into textbox and respective data should be displayed in datagridview..

How to query previous and next record?


hi there,

  i would like to query out the next record and previous record guid from the current record guid.But i don't want to use the ID + 1 or ID - 1  because the ID is not secure for query like this. I am using MS SQL.

May i know how can i write the sql query?  Please give me a guidance.



hope can hear from you all soon. Thank You

Query acting weird.. larger date range works in 1min 26sec and a smaller range say 1 month - 3 month


I have no clue why my query is acting weird

If i try to run it for 1/1/2010 9/30/2010 the query takes around 1min 26 sec and  return around a million rows

and If i run for 8/1/2010 to 8/31/2010 it takes forever to it...

basically i am getting data from 5 tables and putting it in a temp table and then updating that temp table 2-3 times with some information and then displaying it.

I am stumped as to why it works fast for a longer date range and runs the  snail for a small period of time..

I am in the verge of pulling my hair and going crazy..

any help will be appreciated.




Display a message if query returns no data


I added a text box to my report reading: "No Data Matches Search Criteria".  I tried to add a visibility expression: =iif((Rownumber("SalesCube")=0),1,0)

I get "The Hidden expression usied...returned a data type that is not valid"

What am I doing wrong???


query: last login record without a matching logoff record


Hello. I am creating a login/logoff audit program to track / restrict users on our network.

I have a table containing log on/off records so : loginid, userid, logindatetime, state, computername (state is either: 1 logon, -1 logoff or 0 attempted logon)

its probably quite simple but i can't quite get my head around it, i need a query to tell me who is currently logged on, ie the most recent logon (state=1) which has no logoff (state=-1) to match. the trouble is that this must cater for users being able to log on to multiple computers so somewhere the computer names must match too when eliminating records.

i currently have the following query for selecting the most recent logon, but can't think how to eliminate the ones which have a matching logoff

with cte as (
	select *, ROW_NUMBER() over (partition by UserID order by a.LoginDateTime desc) as seq from LoginAuditTable a where a.[State] = 1

imagebutton shows "submit query" before image display


hi guys,

i have imagebutton's on a page with width/height's set and the imageurl pulls from a database

anyway theres 20'ish images on the same page so it takes a second or 2 for the images to load, unfortunately with the imagebutton, while it's in that limbo stage there's 20 big ugly grey SUBMIT QUERY textboxes in my face.


anyone know how to wkraround this? some sort of default already loaded image, or somehow to turn that off altogether? 

Sql query to put data in one sngle record


i have one parent table and one child table.

so in parent table only one records will stay for one bunch of records and remaing records will pushed into child table.so scenario may be like this in MSATER table for one record there may be 3 reords in child table

2-in MSATER table for one record there may be 5 reords in child table

3-in MSATER table for one record there may be 10 reords in child table and so on..

parent table                                                 Child table

id  Student_name   age   phone                 id  Student_rollno   Student_name  FatherNAme
1     manoj        23  42846209862            1       34             manoj           Deepak
						    1       23             ramesh          Kailash
						    1       45             raja              tara	

I want data in this format 	    
id  Student_name   age   phone            FatherNAme1  FatherNAme2 FatherNAme3	
1           manoj    23    42846209862        Deepak     Kailash		tara		

But currently we have 3 records but if I have 10 records then also tha data comes in similar fashion means(	FatherNAme1   coloumns repeat 10 time)
How can I do this.I need to store data in a single row.						


Query Timed Out But Record Inserted



I have a parameterized stored procedure that inserts one record into a table at any one execution. The query timed out but the record was inserted. My question, is it possible for a query to time out and record gets inserted at the same time?

Thanks in advance.


Yong Hwee 

I need to display and group by month/year


I have this date format from



(CHAR(10),(INVC_DT),112) = 20090102 

but I just need the month and year in order to do the aggregations with...

Query to Return Rolling 12 Month Totals



I have a table that looks like this:

[Date], [Person], [Value]

22/03/2008, Person A, 3.1

22/03/2008, Person B, 4.2

03/04/2008, Person B, 5.1

04/04/2008, Person B, 3.0

06/04/2008, Person C, 3.0

I need a query to return a table that shows the totals of each person's value for each month of the proceding 12 months from Date X.  So if Date X is 30/04/2008 then my result table would look like this:

[Month], [Total]

March, 7.3

April, 11.1

Thanks in advance.





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