Transact SQL :: Find Total Days Of Stay From First Arrival To Last Departure Day

Nov 12, 2015

i have a table with customer number, arrival and departure days and days difference between them. i need to find out the total number of days from first arrival day to last departure day if departure and next arrival days are same. for example, for customer Number, 1120, departure date and next arrival days are same, so the total number of days of stay is, 28+28+42+42. how to find out this total suing SQL.

CustomerNumber
ArrivalDate
DepartureDate
Days

1120
10/24/2014
11/21/2014
28

[Code] ....

View 8 Replies


ADVERTISEMENT

Transact SQL :: Total Number Of Days Between Two Dates By Year?

May 6, 2015

I am currently working on a T-Sql query(Sql server 2008) to calculate total no of days between date ranges by year

Table:

Start Date End Date
01/01/2013 04/30/2014
11/01/2014 05/31/2015
06/01/2015 12/31/2015

My expected result.

2013 - 365
2014 - 181
2015 - 365

Note:

Date range can span b/w  multiple years

Date ranges will not overlap

I just want the total number of days covered by the range for each year.

Is there any simple way to do this calculation.

View 9 Replies View Related

Transact SQL :: Split Records If Total Days Greater To 1

Nov 5, 2015

I want to split the data every employeid wise based on fromdate and todate if totaldays>1.

sample output specified below ....but same output required for allthe empid's

create table attendence(EmployeeID nvarchar(20),[From] datetime,[To] datetime,TotalDays float)
insert into attendence values('1417','2015-11-02 22:48:49.450','2015-11-04 22:48:49.450',3)
insert into attendence values('1418','2015-11-04 22:48:49.450','2015-11-04 22:48:49.450',1)
insert into attendence values('1419','2015-11-03 22:48:49.450','2015-11-04 22:48:49.450',2)
insert into attendence values('1420','2015-11-04 22:48:49.450','2015-11-05 22:48:49.450',2)
insert into attendence values('1421','2015-11-01 22:48:49.450','2015-11-04 22:48:49.450',4)

 OP
 -------------------------
 EmployeeID    [From]                          [To]                              TotalDays
 1417          2015-11-02 22:48:49.450         2015-11-02 22:48:49.450             3
 1417          2015-11-03 22:48:49.450         2015-11-03 22:48:49.450             3
 1417         2015-11-04 22:48:49.450          2015-11-04 22:48:49.450             3

View 3 Replies View Related

Transact SQL :: How To Find If User Not Logged In For 45 Days

Nov 20, 2015

I have created table called Login in sql server where i have column usercode, email and login_date (login_date is datetime type)So, i created web application using .net. whenever user logged in, i am allowing based userLoged table and  i am inserting into login table.

login table usercode  email       login_date
001          a@gmail.com    2015-11-18 22:02:41.153
001          a@gmail.com    xxx
.
.
.

I have another table called userLoged where i have column usercode,email and web_access 

UserLoged table usercode email         web_access
001         a@gmail.com   Y

Now, if a@gmail.com (001) is not logged in for 45 days, i need to update web_access to be 'N' how to know if he /she not logged for 45 days.

View 4 Replies View Related

Transact SQL :: How To Find Weekend Days Per Month

May 13, 2015

I want to find the first weekend day, second weekend day, third weekend day and fourth weekend day per month using sql query. This is getting from recurring appointment. If weekdays = 65 means it accepts only saturday and sunday. So I want first, second, third and fourth weekend days for a month using query in sql server 2008...

View 17 Replies View Related

Calculate Total Working Hours Between Days

Nov 15, 2013

I have to calculate the total working hours between days, there hours must get automatically round off to nearest value example:

Date :12-05-2013 time : 4:15 will change to 4.00 and if Date :13-05-2013 time: 4:25 then needs to 4.30 and sum the above total hours and results Total : 8.30 hrs.

View 3 Replies View Related

Reporting Services :: Add One Day Onto Days Total In Expression

Nov 22, 2015

I have a report with an expression to give a calculated field value (VoidDays) as follows:=DateDiff("d",Fields!Void_Start.Value, IIf(Fields!Void_End.Value is nothing, today, Fields!Void_End.Value))I have a number of different codes in the output such as VLOSS, VMAINT, VHOUS etc.When I run my report my days total for VLOSS is always correct but all other values are one day short. In the example shown in image below VMAINT should be 6 days and VHOUS should be 20 days which would then both add up to the VLOSS of 26 days
 
I cant currently fix these days at source for a number of reasons hence I need to fix these on the report output.How can I add one day onto each of my Void Days Total for every code except VLOSS which is always correct.

View 11 Replies View Related

How To Calculate The Total Days Between Open And Close Date

Apr 6, 2006

Hi All,
I have a table call case and case_status have two fields, date and status as below:
date                          status
04/01/2006               open
04/05/2006               closed
04/10/2006               open
04/15/2006               closed
Whenever i open and closed the case, one record is insert into the case_status table.
Now I would need to calculate the total days of the case in storeprocedure.
Anyone can help me please.
Aung

View 5 Replies View Related

SQL Server 2012 :: Split Total Days And Amount Between Start And End Month

Mar 21, 2015

I have the table below and like to create a view to show the no of days the property was vacant or void and rent loss per month. The below explanation will describe output required

For example we have a property (house/unit/apartment) and the tenant vacates on 06/09/2014. Lets say we fill the property back on 15/10/2014. From this we know the property was empty or void for 39 days. Now we need to calculate the rent loss. Based on the Market Rent of the property we can get this. Lets say the market rent for our property is $349/pw. So the rent loss for 39 days is 349/7*39 = $1944.43/-.

Now the tricky part and what im trying to achieve. Since the property was void or empty between 2 months, I want to know how many days the property was empty in the first month and the rent loss in that month and how many days the property was empty in the second month and the rent loss incurred in that month. Most of the properties are filled in the same month and only in few cases the property is empty between two months.

As shown below we are splitting the period 06/09/2014 - 15/10/2014 and then calculating the void days and rent loss per month

Period No of Void Days Rent Loss
06/09/2014 - 30/09/2014 24 349/7*24 = 1196.57
01/10/2014 - 15/10/2014 15 349/7*15 = 747.85

I have uploaded a screenshot of how the result on this link: [URL] ....

Declare @void Table
(
PropCode VARCHAR(10)
,VoidStartDate date
,LetDate date
,Market_Rent Money

[Code].....

View 4 Replies View Related

Find Records For X Previous Days

Jul 13, 2005

On a webform, I have three button ... [7 days]  [15 days]  [30 days]When the user clicks one of the buttons, I want to return their orders for the past X days. The WHERE clause would include something like this (for 7 days):WHERE (Order_Date BETWEEN CONVERT(DATETIME, GETDATE() - 7, 102) AND CONVERT(DATETIME, GETDATE(), 102))How do I parameterize the number of days?Thanks,Tim

View 2 Replies View Related

How To Find 'x' Number Of Days From 'yyyymmdd' Format?

Nov 15, 2004

I need to find out the count of number of records older than 100 days from a table having 'order_date' as yyyymmdd format eg. 20041115. Thanks in advance.

View 9 Replies View Related

How To Find Total In A Table?

Dec 7, 2007

I have created a report as shown below using OLTP tables.












No
Description
CA
PA
Variance

10101
Bank of Tampa
388353.69
208048.92
87%

10104
Wachovia Operating
275933.37
-
0%

10105
Wachovia Payroll
217.95
-
0%

10201
Accounts Receivable
16735.60
34829.14
-52%

20002
Account Payable
-175919.72
-106018.68
66%

Now I want to insert total in the middle of the table, like I want to display:
Total of CA when No in (10101,10104,10105) as 'Total Cash'
then
I want to display total of 'Total Cash' + 'Accounts Receivable'(10201) as 'Cash & Receivables'











No
Description
CA
PA
Variance

10101
Bank of Tampa
388353.69
208048.92
87%

10104
Wachovia Operating
275933.37
-
0%

10105
Wachovia Payroll
217.95
-
0%


Total Cash
664505.01



10201
Accounts Receivable
16735.60
34829.14
-52%


Cash & Receivables
681240.61



20002
Account Payable
-175919.72
-106018.68
66%

How do I do this?

View 7 Replies View Related

Inline View To Find Arrivals Within Days Period

Oct 4, 2013

I have this query:

SELECT a.*
FROM Unscheduled_Arrival a INNER JOIN (SELECT Person_ID
,[arrival date]
,[leaving date]
,[unique stay id]
,[area code]
FROM Unscheduled_Arrival

[Code] ....

And what I am trying to do is find instances where a person has arrived back at a different area within 7 days of leaving from a planned visit to any other area different from the last. so lets say we had person ID = 1 and they had had 3 planned visits to one area (not equal to area_gh) in the last 4 months but after the 2nd planned trip to the other area, and before the commencement of the 3rd planned trip to any area not equal to area_gh, they had arrived unscheduled to area_gh, and this unplanned visit was within 7 days of leaving the 2nd last planned visit to any area not equal to area_gh.

The query I have shows data from unscheduled arrivals to the area_gh for a person who has also had visits to any area other than area_gh, but each record for unscheduled visits to area_gh duplicates for the amount of times the person has had scheduled visits to any area not equal to area_gh. This is the first problem but is as a result of not having the correct SQL for the refinement of the data.

This refinement requires that I return only the data that relates to the unscheduled arrival that is within 7 days of the last scheduled arrival, not duplicate rows of area_gh visits for all the scheduled arrivals.

Because my data is showing the data I want but the count is related to the scheduled arrivals I think I need to rewrite the query or alter it.

The data is already restricted to a year's worth of data.

I just need to find any instances of unscheduled arrivals (for arrival at area_gh) within 7 days of the end of any scheduled arrival (determined using leaving date) to area equal to area_gh.

There can be any number of scheduled arrivals and any number of unscheduled arrivals for each person. The [unique stay id] is distinct for each visit so person 1 can have 3 stays, all with a different [unique stay id].

View 3 Replies View Related

Power Pivot :: Cumulative Total For Current Week Days And Previous Week

Nov 30, 2015

We are trying to compare our current calendar week (based on Monday being the first day of the week) with the previous calendar week. 

I'm trying to produce a line chart with 2 axis:

- x axis; the day of the week (Mon, Tues, Wed etc - it is fine for this to be a # rather than text e.g. 1 = Mon, 2 = Tues etc)
- y axis; the cumulative number of orders 

The chart needs two series:

Previous Week. The running count of orders placed that week. 
Current Week. The running count of orders placed this week. 

Obviously in such a chart the 'Current Week' series is going not going to have values along the whole axis until the end of the week. This is expected and the aim of the chart is to see the current week compares against the previous week for the same day. 

I have two tables:

Orders TableCalendar Table

The calendar table's main date column is [calDate] and there are columns for the usual [calWeekNum], [calMonth] etc. 

My measure for counting orders is simply; # Orders: = countrows[orders].

How do I take this measure and then work out my two series. I have tried numerous things such as adapting TOTALMTD(), following articles such as these:

- [URL] ...
- [URL] ...

But I have had no luck. The standard cumulative formulas do work e.g. if I wanted a MTD or YTD table I would be ok, it's just adjusting to a WTD that is causing me big issues.

View 3 Replies View Related

T-SQL (SS2K8) :: Query To Find Older Date That Is Less Than 90 Business Days

Feb 12, 2015

select DateAdd(dd,-90,getdate())

It gives the 90 days older date but i want to exclude the weekdays and holidays (saturday ,sunday,holiday)

As we dont have permission to call a function or Sp in high level environments looking for a simple query .

View 1 Replies View Related

Analysis :: SSAS 2012 - MDX To Find Last 7 Days Data In Where Clause?

Jul 6, 2015

I have a MDX query , where I have a date Range in where clause.

I want to replace it with Cuurent Date and Last 7 days date.

I tried multiple ways using NOW function , but could not get it correct .

modifying the Query so that I can fetch DATA for last 7 days 

SELECT NON EMPTY { [Measures].[X] } ON COLUMNS, NON EMPTY { ([PRODUCT].[PRODUCT].[PRODUCT].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( { [COLOR].[COLORName].&[BLACK], [COLOR].[COLORName].&[BLUE] } ) ON COLUMNS
FROM ( SELECT ( [Date].[Calendar].[Calendar Year].&[2015].&[2015]&[3].&[7].&[20150706] : [Date].[Calendar].[Calendar Year].&[2015].&[2015]&[2].&[6].&[20150629] ) ON COLUMNS
FROM [MYCUBE]))

I want to replace Date Hard code value , I have used Calendar Hierarchy of date dimension. to find Last 7 days Data.

View 2 Replies View Related

Urgent: How To Find Total No. Of Queries In SQL Server 7

Sep 12, 2000

Is there a way to find out total number of queries ran i.e by day/hour or since the database was brought up in SQL Server 7?


Thanks in advance,

View 1 Replies View Related

SQL 2012 :: Find Total Disk Size

Nov 21, 2014

We can find free space on disks with 'xp_fixeddrives'.

I need script to find all disk size(total sizecapacity) in the servers?

View 9 Replies View Related

New Arrival Of *** Removed ***

Apr 13, 2007

*** Product Removed **** is a rendering extension for Microsoft SQL Server 2005 Reporting Services that allows exporting reports in the DOC, RTF and WordprocessingML formats. All RDL report features, including tables, matrices, charts, textboxes, lists and images are converted with the highest degree of precision to Microsoft Word documents.

Read More at: *** URL Removed ****

Download Link: *** URL Removed ***

Post your queries and questions to *** Product Removed Forum: *** URL Removed ***


Contact Information:
*** Got rid of this too ***

View 1 Replies View Related

Rolling Sum To Find Total Of 3 Previous Months Gas Production

Nov 5, 2012

I'm in need of creating a rolling sum to find the sum of 3 previous months gas production. Below is an example of the basic data I will be using to find the sum.

OperatorIDRRCID YearReported MonthReported YearCode DateReported GasProduction
71054993207201222012022012-02-01 89
71054993207201212012012012-01-01 721
710549932072011122011122011-12-01 353
710549932072011112011112011-11-01 409
710549932072011102011102011-10-01 544
71054993207201192011092011-09-01 707
71054993207201182011082011-08-01 506
71054993207201172011072011-07-01 536
71054993207201162011062011-06-01 472

I want the sum of the Year & Month of 2012-2 to be the sum of the gas production for 2012-1, 2011-12, and 2011-11.

View 1 Replies View Related

Transact SQL :: Select Between Days Record Of Every Month

Jun 29, 2015

I have 3 month of record in my table. if i pass 2 and 10, i need to select the record of between 2 and 10 days of record of every month. if i pass 10 and 20, it should select the record between 10 and 20 of every month. How to query for that?

View 8 Replies View Related

Transact SQL :: Display All Days Of A Given Month And Year

Oct 17, 2015

I need a simple query to display all the days of a given month and year

View 2 Replies View Related

Transact SQL :: Calculating Date Difference In Days

Apr 16, 2015

I'm trying to calculate the time difference between a date field and today's date in days. The date field is not mandatory and can therefore be blank. I'm trying to execute the following query:

SELECT employee_code, Civil_ID, DATEDIFF(Day, Civil_ID, GETDATE())
FROM ODEV_VIEW_Credentials_Expiry_Dates
WHERE Civil_ID IS NOT NULL AND Civil_ID != ''
ORDER BY employee_code

I keep getting the following message:

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

Warning: Null value is eliminated by an aggregate or other SET operation.

No matter what filter I use to process non-blank dates, it never works.

View 12 Replies View Related

Transact SQL :: Displaying POs With Due Dates Greater Than Three Days

Apr 24, 2015

What I want to see is how to show PO's who's due dates  are > three

Select * from mytable
where myorderstatus = 'onorder'

This is my duedate format and what I want is any that past that date over 3 days

2014-08-11 00:00:00.000

View 11 Replies View Related

Transact SQL :: Number Of Days Between A Date And Its Month End

Sep 23, 2015

I have a column which stores a set of dates. I want to tell how many days left of a date till it’s month end. It should be noted that month ends are taken from the date series, not a calendar month end.
 
Something like below,
 
DateTD       Days left
2009-01-05  14
2009-01-06      13
2009-01-07      12
2009-01-08      11
2009-01-09      10
2009-01-12       9
2009-01-13       8
2009-01-14       7
2009-01-15       6
2009-01-16       5
2009-01-19       4
2009-01-20       3
2009-01-21       2
2009-01-22       1
2009-01-23       0
2009-02-02       /
2009-02-03       /

View 28 Replies View Related

Transact SQL :: User Defined Number Of Days

May 8, 2015

I am new to sql server query. I am trying to write a query for an application and I want user to enter number of over due days for payment.Below is my query and I am getting an error: An expression of non-boolean type specified in a context where a condition is expected, near 'Group'.

SELECT (P.FirstName+', '+P.LastName) As PA, Px.PRespDate,Px.DateFrom
 WHERE Px.Hide = 0 AND Px.Total <> Px.Payments AND Px.PRespDate IS NOT NULL AND PE.Hide = 0 AND PE.BillReady = 1 
AND DATEDIFF(DAY, Px.DateFrom, PRespDate)  LIKE 'Enter # of days |%% '
Group By (P.FirstName+', '+P.LastName), Px.PRespDate,Px.DateFrom

View 2 Replies View Related

Transact SQL :: Calculating Duration In Days For Generic From And To

Oct 7, 2015

I need the SQL to calculate the duration between a day and time, no specific date. 

For example:
Sun 00:00 > Mon 08:00 = 5.67 days

So there is no date, it's just the general duration  (in days), from a specific day and time to a specific day and time.

View 3 Replies View Related

Transact SQL :: Count Of Same UserID Used Within 7 Days For That Month

Nov 19, 2015

I want to find out count of same UserID used within 7 days for that month.

For example, in below scenario, UserID 458's 1st TTo is 8/26/2015 and it used again on 8/28/2015 which is less than 7 so result should be 1. (DateDiff between 1st TTo and 2nd Tfrom should be less than 7) This is for month of Aug.

ID TFrom TTo
9876 8/1/2015 8/7/2015
4140 8/21/2015 9/4/2015
458 8/23/2015 8/26/2015
458 8/28/2015 9/8/2015

Scenario 2,for UserId 458, TTo is 9/20 and it used again Tfrom on 9/20 so result should be 1 

user ID TFrom T To

592 9/1/2015 9/24/2015
526 9/3/2015 9/11/2015
292 9/11/2015 9/25/2015
352 9/12/2015 9/24/2015
458 9/14/2015 9/20/2015
458 9/20/2015 10/2/2015
706 9/22/2015 10/6/2015

View 5 Replies View Related

Transact SQL :: Show Total For Each Name

Sep 23, 2015

I tried my syntax below, but it said that the field were not in the group by.  This is syntax and for each of the 2 names (only small subset of real data) I need a Total column to display between each different person like so:

Total, 29, 150, 2400/60
Total, 25, 143, 2400/60

Here is syntax:

Create Table #Farquard
(
empID varchar(50),
fullname varchar(500),
break1 int,
break2 int,
dailytotal int,
workday date
)

[Code] ......

View 8 Replies View Related

Transact SQL :: How To Get Total Value As A Column

Jul 14, 2015

I have a table like below, which is  contain area, zone, branch wise value. In that i want to get company total as a column and area total as a another column and zone total in next column

AREAZONEBRANCHVALUE
TNCENTRALAMB100
TNCENTRALTNF100
TNCENTRALSDGD100
TNCENTRALERW100
TNNORTHAMB50

[Code] ....

My expected output is like below

AREAZONEBRANCHVAL comtot areatot zonetot
TNCENTRALAMB1001200560400
TNCENTRALTNF1001200560400
TNCENTRALSDGD1001200560400

[Code] ...

I achieved this by using query but its will affect performance because my real time scenario dealing with laks of records

select a.*,b.company_tot,c.area_tot,d.zone_tot from FESIBILITY_CHECK a cross join (select SUM(value)company_tot from FESIBILITY_CHECK )b
join (select SUM(value)area_tot,area from FESIBILITY_CHECK group by area)c on a.AREA = c.area
join (select SUM(value)zone_tot,area,zone from FESIBILITY_CHECK group by area,zone)d on a.AREA=d.area and a.ZONE = d.ZONE

So I planned to use cube and roll up but i don't get desired result ...

View 8 Replies View Related

Transact SQL :: Displaying Total Row

Sep 2, 2015

My query below displays a total row, but it displays above the city, I want it to display below the city. But now their is an additional caveat, I have a table that sets the order each city & total row should display in.  How can that be added to my query to set the display order?This is what I have that displays the total above the city, could this be ammended to join in the order table and display in that order?  SQL Server 2008

Create Table studentdata
(
homecity varchar(100),
usernumber int,
userstatus varchar(100),
usernumbermanager varchar(100)

[code]....

View 8 Replies View Related

Which Is The Most Efficient Query To Find Out The Total Number Of Rows In A Table?

Mar 30, 2006

which is the most efficient query to find out the total number of rows in a table other than using - SELECT COUNT(*) ... in query

View 10 Replies View Related

DB Engine :: Find Total Memory Allocated To Server And CPU Utilization

Apr 30, 2015

I am searching for query to find total memory allocated to sqlserver,  and how much being used utilized as well cpu utilization percentage . 

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved