.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

Sql query from 4 different dates

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

its easy to combine and collect data between two dates but my problem is quet difficult and amazing as well. i have to collect data from 4 differet days  which are in sequence means first from 6am to 6pm second day 6am to 6pm  thirdday from 1800 to forthday 6am and from forth day 1800 to fifthday 6am meam collection of data for one shift. presenly   i am calculating data from this query but only for one day either day or night. and seperatly. but on four pages but i want to collect all out put on one page i know its not difficult for my expert brothers who will hepl me indeed.....................eric

my presend query is this.................


 @ShiftDate Datetime,
 @Shift_D_4_Day_N_4_Night char(1),
 @Shift_0_1_29 int
-- @EndDate Datetime

SELECT     TOP (100) PERCENT COUNT(*) AS Quantity, dbo.System.Type, dbo.Room.RoomID, dbo.GetLineLU(RoomID)As RoomWrkIDID, dbo.GetDayDate(dbo.Room.Datestamp) As "Day_Date", dbo.GetShift(dbo.Room.Datestamp) AS "Date|D/N"
FROM         dbo.Room INNER JOIN
                      dbo.System ON dbo.R

View Complete Post

More Related Resource Links

QUERY filter dates by DAY

i have the following data : first column: dates and 2nd column: values i want to filter the dates per day and calculate the AVERAGE of their values per day i can filter them manually by setting day(datetimefield) = 12 and calculate the AVERGAE but i dont know how to do it for all in one query? each record resulting the average of that day   2010-07-12 00:00:00.000 900 2010-07-12 10:00:00.000 1000 2010-07-12 10:10:00.000 1200 2010-07-12 12:00:00.000 1100 2010-07-12 15:00:00.000 1300 2010-07-12 15:10:00.000 1500 2010-07-13 00:00:00.000 6500 2010-07-13 10:00:00.000 5500 2010-07-14 00:00:00.000 5500 2010-07-14 10:00:00.000 4400 2010-07-15 10:00:00.000 4500 2010-07-16 00:00:00.000 1000 2010-07-17 00:00:00.000 7000 2010-07-18 00:00:00.000 8500 2010-07-19 00:00:00.000 1500 2010-07-20 00:00:00.000 1700 2010-07-21 00:00:00.000 1900 2010-07-22 00:00:00.000 2000  

Multiple Dates Query


I need help in creating a query to get info for year selected and previous year of the year selected. Needs to be by quarter(QTR) for both years. QTR1 will always be the month 03, QTR2 month 06, QTR3 month 09, & QTR4 month 12. No computations are required or averaging.

Fields/columns are YEARMONTH stored as mm/dd/yyyy with dd always being 01, ACTUAL_MONTH(float)for all QTRs based on current YEARMONTH selected and one year prior,TARGET_MONTH(float) for all QTRs based on YEARMONTH selected, and PROJECTION_MONTH(float) for all QTRs based YEARMONTH selected.

YEARMONTH (PK, Datetime)

Should look like this if any YearMonth in 2010 was selected
                   Q1 Q2 Q3 Q4
09-Actual      xxx xxx xxx xxx
10-Actual      xxx xxx xxx xxx
10-Target      xxx xxx xxx xxx
10-Projection xxx xxx xxx xxx

SQL Query for Date Check User Dates



I am using two columns in one table such as StartDate,Enddate.

In asp.net Form two text boxes there. One is StartDate other one EndDate..

When user Click Submit button the Two dates is compare above DataFiled's...


-------- Data Base Values ----------------

StartDate            EndDate


10/09/2010         14/09/2010

16/09/2010         28/09/2010



user send Start Date ' 27/09/2010' and EndDate '30/09/2010'


Now the Query Check Dates Between Userdates avialable in Database....


What I ll do?????


(Note : Opertion only allow the Dates Not Exists in Database Dates)



query wich returns records for each day between start date from table 1 and mutation dates in table



I have to tables with dates, table Employments with all employements of all employees, with start date and end date, and a table Mutations with mutations (e.g in salary) with start dates.

Now I try to write a query which returns a record for each day an employee is in employment, with the correct salary. SO at first, it should return all days between the employment start date and the first mutation date, then the number of days between the first mutation date and the second mutation date etcetc, and at last the number of days between the last mutation date and the employment end date. The number of mutations varies for each employment, and employees cna have multiple employments (history, so not at the same time) in the employments table.

How to do this?

Select Query For Dates comparision


Data is like this in one table.Those are dates but values are VARCHAR datatype



How to write a select query by passing  two parameters Dates between @StartDate and @EndDate . But From Front end values are passing like below for example

01-Jan-2010 and 31-Dec-2010

How to write a select which consider dates in above format and gives correct results.




MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Content Query Web Part missing in SharePoint 2010

If you don't see content query web part listed in the web parts list, this is because you have not enabled "Search Server Web Parts" feature in site collection features. Enable this feature and content query web part will show in the list of web parts.

sql query that don't run



I'm going crazy... i've got a piece of code that don't update the database... Could somebody tel me why it doesn't run??

Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim cmdstring As String = "Update Corsi Set [Contenuto]='" & TxtText.Content & "' Where [ID]='" & Request.QueryString("Id").Replace("'", "") & "'"
        conn = New SqlConnection(SqlAnni.ConnectionString)
        cmd = New SqlCommand(cmdstring, conn)

Need help with a linq to sql query


I want to display some stats in a listview contril.  The table contains a record for every impression and for every click, and every record has a datetime field for the time and date of the impression of click.  I want to be able to display how many impressions and clicks there were in a given day and hour, something like below:

Date              Time                              Impressions    Clicks
8/20/2010                                               450              14            
                     Midnight -1:00am               150               5

How to send an email with information in query string


First I will say I googled (Binged to make Bill happy) for this but could not find anything, perhaps I am not stating what I need correctly;

I have a website that a customer creates orders (for a printing company) and after the order, I would like to email the customer a link to view the status of their order;

I need to send the CustomerID in the link so on the returning page if a CustomerID is detected in the querystring, I "auto login" the client and open the "Dashboard" for the order page for that customer.

Can anyone point me in the right direction as to how to send the link and how to parse the querystring to get the values from the link;

Thank you if you can point me in the right direction.

MDX Query parameter from SSRS


I've a MDX Query that has where clause as shown below.
I'm designing report using SSRS 2008. How can i pass date as parameter ? I tried to setup @from and @to as parameter but not working ?
any ideas....

WHERE ( {[Date Central].[Calendar Date].[2010-04-01 00:00:00]:[Date Central].[Calendar Date].[2010-08-30 00:00:00]} )

need it to work as
WHERE ( {[Date Central].[Calendar Date].[@From]:[Date Central].[Calendar Date].[@To]} )



Get ServerReport selected Parameter value to use in vb query


I'm using ReportViewer in Asp.net 2.0 to view a SSRS report. I need the value of the selected parameter to use in a vb query. The parameters are populated on the server and its a single selection. Doing searches I've come across  ReportViewer1.ServerReport.GetParameters() but I can't figure out if I can use this to determine which value the user has selected in the parameter dropdownlist. Any help would be appreciated.

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 &&

Query an arraylist of array list using linq


I have an array list called Customer. I t holds a list of array list which has the account details.

proj.customer -> collection of arraylist of type customer

proj.customer.account -> collection of arraylist of type account

Account array list holds type account and it has a poperty account balance. How can I query all accounts which has account balance  >100

I tried the following one

var Accountlist= from Account accountdetails in proj.customer.account

where accountid.balance >100

select accountdetails.id

But it is always throwing an error saying cannot cast type customer to type account

Please help

Basic Instincts: Increase LINQ Query Performance


Jared Parsons demonstrates a technique to achieve maximum performance from LINQ queries on large sets of data in order to create a responsive user interface.

Jared Parsons

MSDN Magazine August 2008

Data Points: Standard Query Operators with LINQ


LINQ to Objects and LINQ to Entities have an arsenal of Standard Query Operators that operate on sequences to perform a wide variety of operations.

John Papa

MSDN Magazine March 2008

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