Catch Date Gaps In Different Records
Jan 30, 2005
I need to write a procedure to check if I have any gaps in my dates...
Start Date............End Date
10/6/2004............10/6/2005
10/6/2003............10/6/2004
7/10/2003..........10/6/2003
7/10/2002.............7/10/2003
What I need to do is test the End Date to the next row under the Start Date Column. (in bold to clarify) (moving upward from bottom)
sSQL011$ = "SELECT * FROM TableName " & _
"WHERE ID = '" & ID & "'"
Set rs011 = DB.OpenRecordset(sSQL011$, dbOpenDynaset)
Set Data1.Recordset = rs011
rs011.FindFirst "ID = " & ID
With rs011
do while .eof = False
if .eof then
exit sub
end if
if rs011("StartDate") 'from one record, if it is not equal to the Start
Date in the next record then
MsgBox "Gap in Dates for: " + ID
loop
end with
pseudo...
if the end date in one consecutive row is not the same as the start date in the next row then there is a date gap
thanks...
View 3 Replies
ADVERTISEMENT
Feb 23, 2006
Hi to all,
I'm a new member here and i would like to ask for some help regarding my problem. first i ahve an incremental primary key with format to something like this: 001-01-001, 001-01-002, 001-01-003, etc. My problem is that i want to insert (supply) the 'missing' or 'gaps' in my primary key field like for example: ..., 001-01-067, 001-01-068, 001-01-070. i want to insert the value 001-01-069 after the record 001-01-068. I have several gaps some ranging from several numbers like 005-04-007,005-04-020 which has a 13 records gap. Is there a way for stored procedure to solve this one?Thanks in advance.
View 8 Replies
View Related
Jan 17, 2008
I have a table with the following specifications:
[FutureArticleId] [bigint] IDENTITY(1,1) NOT NULL,
[cFutureArticleTitle] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[cDescription] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[gCategoryId] [bigint] NOT NULL,
[cKeyword] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[bIsDeleted] [bit] NOT NULL CONSTRAINT [DF_tbl_FutureArticle_bIsDeleted] DEFAULT ((0)),
[tOnCreated] [datetime] NOT NULL,
[tOnUpdated] [datetime] NULL,
[gCreatedBy] [bigint] NOT NULL,
[gUpdatedBy] [bigint] NULL,
After some insertions and deletion from the UI, obviously there are gaps in the FutureArticleId column which is an identity column.
However, sometimes while inserting the records the records are being inserted into the gap and not in the next available Identity value.
Is there any table setting which I need to do, to stop this.
Please let me know
Thanks
Ankit
View 3 Replies
View Related
Mar 5, 2008
Hi,
I have a table with date ranges for activitys. I need to get the userid , firstdayidle, lastdayidle for when a user has been idle in the last 90 days.
it gets tricky since it also must include users that have no records in activity table or only one record so it has 2 idle periods, etc
I have a hard time wrapping my head around the logic, weither using a datetables or not, so any help would be appreaciated
--my first step is to get the activitys that enter the last 90 days
select * from Activity2
where (enddate > DateAdd(d, -90, getDate()) AND enddate < getDate()) OR (startdate > DateAdd(d, -90, getDate()) AND startdate < getDate())
CREATE TABLE [dbo].[InternalUser](
[userid] [int],-- IDENTITY(1,1) NOT NULL,
[fullname] [varchar](50)
}
insert into [InternalUser] values(1,'a')
insert into [InternalUser] values(2,'b')
insert into [InternalUser] values(3,'c')
insert into [InternalUser] values(4,'d');
insert into [InternalUser] values(5,'e');
insert into [InternalUser] values(6,'f');
CREATE TABLE [dbo].[Activity2](
[activityid] [int] NOT NULL, --IDENTITY(1,1)
[userid] [int] NOT NULL,
[startdate] [datetime] NULL,
[enddate] [datetime] NULL
)
insert into [Activity2] values(1,1,'2007-02-15 00:00:00.000','2008-03-15 00:00:00.000')
insert into [Activity2] values(2,2,'2007-01-01 00:00:00.000','2008-01-02 00:00:00.000')
insert into [Activity2] values(3,2,'2008-01-20 00:00:00.000','2008-04-10 00:00:00.000')
insert into [Activity2] values(4,3,'2008-02-20 00:00:00.000','2008-10-10 00:00:00.000')
insert into [Activity2] values(5,4,'2007-01-01 00:00:00.000','2008-01-16 00:00:00.000')
View 5 Replies
View Related
Sep 13, 2013
I have a group of date ranges and wanted to identify all of the date gaps within the ranges, outputting the dates as another date range dataset.
Example dataset SQL below:
CREATE TABLE #test (daterow int identity, obj_id int, datestart DATETIME, dateend DATETIME)
INSERT INTO #test
SELECT 1, '20130428', '20130523'
UNION
SELECT 1, '20130526', '20130823'
[Code] ....
I would expect a dataset to be returned consisting of:
1, 24/05/2013, 25/05/2013
1, 24/08/2013, 25/08/2013
2, 16/05/2013, 24/05/2013
I have found a lot of examples of problems where I have just a single date column, and then I find the gaps in between that, but I'm having difficulty finding examples where it works with start and end date columns...
View 9 Replies
View Related
Dec 10, 2014
See sample data below. I want hourly breakdown for the last X years, the month and day will be the same for each year.
SELECT '2013-12-10 04:00:00.000' as dt, 220.50 as amt UNION ALL
SELECT '2013-12-10 06:00:00.000' as dt, 24.50 as amt UNION ALL
SELECT '2013-12-10 07:00:00.000' as dt, 527.50 as amt UNION ALL
SELECT '2013-12-10 08:00:00.000' as dt, 28.50 as amt UNION ALL
SELECT '2013-12-10 11:00:00.000' as dt, 25.50 as amt UNION ALL
[Code] .....
-- expected result
SELECT '2013-12-10 00:00:00.000' AS dt, NULL AS Amt UNION ALL
SELECT '2013-12-10 01:00:00.000', NULL AS Amt UNION ALL
SELECT '2013-12-10 02:00:00.000', NULL AS Amt UNION ALL
SELECT '2013-12-10 03:00:00.000', NULL AS Amt UNION ALL
SELECT '2013-12-10 04:00:00.000', 220.50 AS Amt UNION ALL
[code].....
View 9 Replies
View Related
Jul 23, 2005
I have a table containing typed log entries. One log entry is supposedto be created every twelve hours, but sometimes there are gaps. I needto create a report showing the time of entry, and the actual log entry.I can't just list the contents of the log table, because if I do thatthere will be dates missing. Instead, when there isn't a log entry fora date, I need to print the date, and then just leave the log entryblank.The SQL bellows shows what the output should look like. HOWEVER, thecode below makes use of a temp table containing all possible dates. Myquestion is, is there a better way to do this - one that doesn'tinvolve the temp table? Thanks in advance.create table StationLog (LogDate datetime, LogText char(11))insert StationLog values ('1/1/2005 00:00:00','entry one')insert StationLog values ('1/1/2005 12:00:00','entry two')insert StationLog values ('1/2/2005 00:00:00','entry three')insert StationLog values ('1/3/2005 00:00:00','entry four')create table Date_List (TempDate datetime)insert Date_List values ('1/1/2005 00:00:00')insert Date_List values ('1/1/2005 12:00:00')insert Date_List values ('1/2/2005 00:00:00')insert Date_List values ('1/2/2005 12:00:00')insert Date_List values ('1/3/2005 00:00:00')insert Date_List values ('1/3/2005 12:00:00')select TempDate, LogTextfrom Date_Listleft outer join StationLog on Date_List.TempDate = StationLog.LogDatedrop table StationLogdrop table Date_List
View 6 Replies
View Related
Jul 4, 2007
I use the following function (in the BLL) to delete some records:
Public Function DeleteStep4Dashboards() As Boolean
Try
adpDashboards.DeleteStep4Dashboards()Catch ex As Exception
Return False
End Try
Return True
End Function
How can I catch the sql database errors when deleting the records goes wrong.
View 5 Replies
View Related
Mar 8, 2004
hi,
I try to write a function which includes a statement:
SELECT @dateReturn = CAST(@dateString As datetime)
to convert a string to datetime.
When it runs, sometime it will generate :
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."
and all related are terminated.
Can I find a way to catch this error and don't let it terminate the whole thing? For
example, when this happens, I want to get datetime as NULL instead of just being
terminated.
Thanks.
View 1 Replies
View Related
Feb 15, 2007
Hi,
I'm having trouble with a Script Component in a data flow task. I have code that does a SqlCommand.ExecuteReader() call that throws an 'Object reference not set to an instance of an object' error. Thing is, the SqlCommand.ExecuteReader() call is already inside a Try..Catch block. Essentially I have two questions regarding this error:
a) Why doesn't my Catch block catch the exception?
b) I've made sure that my SqlCommand object and the SqlConnection property that it uses are properly instantiated, and the query is correct. Any ideas on why it is throwing that exception?
Hope someone could help.
View 3 Replies
View Related
Aug 5, 2015
I'm looking for a way of taking a query which returns a set of date time fields (probable maximum of 20 rows) and looping through each value to see if it exists in a separate table.
E.g.
Query 1
Select ID, Person, ProposedEvent, DayField, TimeField
from MyOptions
where person = 'me'
Table
Select Person, ExistingEvent, DayField, TimeField
from MyTimetable
where person ='me'
Loop through Query 1 and if it finds ANY matching Dayfield AND Timefield in Query/Table 2, return the ProposedEvent (just as a message, the loop could stop there), if no match a message saying all is fine can proceed to process form blah blah.
I'm essentially wanting somebody to select a bunch of events in a form, query 1 then finds all the days and times those events happen and check that none of them exist in the MyTimetable table.
View 5 Replies
View Related
Jun 6, 2012
I need to compare the contents of a column.
I have a table with 1 column. Below are the sample contents..
DateInterval
2012-06-01 00:30:00.000
2012-06-01 01:00:00.000
2012-06-01 01:30:00.000
2012-06-01 02:00:00.000
2012-06-01 02:30:00.000
[code]....
as you can see, the records have a 30minutes time interval. i need to create a query to know if there are missing records in the table. so basically the result should be this:
DateInterval
2012-06-01 18:00:00.000
2012-06-01 20:30:00.000
if it is not doable, we can get the nearest record of all missing records like this:
DateInterval
2012-06-01 17:30:00.000
2012-06-01 20:00:00.000
or this:
DateInterval
2012-06-01 18:30:00.000
2012-06-01 21:00:00.000
or this:
DateInterval
2012-06-01 17:30:00.000
2012-06-01 18:30:00.000
2012-06-01 20:00:00.000
2012-06-01 21:00:00.000
View 6 Replies
View Related
May 15, 2007
hi all,
All of a sudden my application started crashing when trying execute dml statements on sql server mobile database (sdf file). Frustating thing is that whole application crashes without any error message. this happens for all kinds for DML statement but not all the time. Sometimes it would fail for delete statement such as delete from table; or for insert into statement
my problem catch does not catch the error. There is no way to find out teh what is causing this error
SqlCeConnection sqlcon = new SqlCeConnection("
Data Source = '\Program Files\HISSymbol\HISSymboldb.sdf';"
);
SqlCeCommand sqlcmd = new SqlCeCommand();
sqlcmd.CommandText = Insert into company('AA', 'Lower Plenty Hotel');
sqlcmd.Connection = sqlcon;
SqlCeDataReader sqldr = null;
try
{
sqlcon.Open();
//use nonquery if result is not needed
sqlcmd.ExecuteNonQuery(); // application crashes here
}
catch (Exception e)
{
base.myErrorMsg = e.ToString();
}
finally
{
if (sqlcon != null)
{
if (sqlcon.State != System.Data.ConnectionState.Closed)
sqlcon.Close();
sqlcon.Dispose();
}
}//end of finlally
View 4 Replies
View Related
Aug 30, 2007
Greetings,
I am new to SQL Server. I've created a database with a key ID field that is set to automatically increment. Well, after adding records I've got some gaps in my numbering and want to renumber from 1 to eof.
What is the best way to do this in SQL Server 2005?
Thank you.
View 4 Replies
View Related
Dec 13, 2004
hello, i have quite a challenge on my hands here and would appreciate any help. :confused:
I have a table variable that stores integer ranges representing times of the day:
select * from @reservations
room date | starttime | endtime
1 2004-12-11 0 1440 (represents an entire day in minutes)
2 2004-12-12 420 1020
3 2004-12-14 200 600
4 2004-12-15 0 200
4 2004-12-15 500 1000
I need to be able to return the minutes that are open for each room. The @reservations table shows me the times that are blocked.
I'd like to analyze each row and return an integer range representing gaps in the day, where 0-1440 represents an entire day.
Based on the @reservations table above, I'd like to write something that returns:
room date starttime endtime
2 2004-12-12 0 420
2 2004-12-12 1020 1440
3 2004-12-14 0 200
3 2004-12-14 600 1440
4 2004-12-15 200 500
4 2004-12-15 1000 1440
This result represents the times in minutes that are available.
I have no clue how to do this without using a numbers table and checking each minute in each day for each row in the table. Id like to not do that because of sheer performance reasons. There is a possiblity that I will have hundreds of rows in the @reservations table.
I was hoping someone could provide some insight as to how to approach this. Thank you ahead of time! :)
View 3 Replies
View Related
Apr 6, 2008
Hi,
I have a table with an identity column..How will the identity gaps be adjusted if i delete few records in the table..ie..the sequence should automatically adjusted..Is there any way for this ?
ID Name City
1 abc xyz
2 mexm mcel
3 olekc kcome
Suppose i delete the record where ID=2..still the sequence should be auto adjusted..ie.the record of ID=3 should become ID=2 automatically..there shouldn't be any gaps.
View 8 Replies
View Related
Jul 20, 2007
I have a row in my report that has 6 columns. I want to outline the row with a border, but not the column lines in between. So, I went into BorderColor, changed the Default to white and my Top and Bottom colors as Black. The problem is that where the "white" column lines are, they are displaying 1pt gaps in my outline. I tried changing the BorderStyle to Zero, but it wouldn't take it.
See sample of the report here.
Any ideas?
Thanks,
James H.
View 6 Replies
View Related
Jan 14, 2008
Hi developers and architects,
I would like to know if it's possible to do "a gap to the left" in transact sql...
I have a table with:
ID Level1 Level2 Level3 Level4
1 NULL NULL 1 2
2 NULL 1 2 3
My results should be:
ID Level1 Level2 Level3 Level4
1 1 2 2 2
2 1 2 3 3
Currently I'm using a cursor to do that but I haven't good performance.
Do you have ideas?
Thanks a lot,
Jérémie
View 3 Replies
View Related
Jan 31, 2008
When I try to export my new report to PDF, I get extra blank lines in my list(s). My report has a list, with another list inside of it (among other textboxes). When I generate the report, or print it to a printer, it prints as expected. If I export to PDF, it adds in a bunch of blank lines into some of the inner lists. It doesn't seem to reflect any issue with the data, but it is consistent where it puts the spaces. Anyone know of any settings I might be missing?
View 3 Replies
View Related
Apr 9, 2008
this is my sample records in my table
Sdate       Amount
January 2007 Â Â 250000.00
March 2007 Â Â Â 300000.00
January 2008 Â Â 350000.00
how can i get the amount from January to
May 2007 and sum it up like this
Details
January 2007 Â Â 250000.00
February 2007 Â 250000.00
March 2007 Â Â 300000.00
April 2007 Â Â 300000.00
May 2007 Â Â 300000.00
this is all that i want to get
Total Amount: 1,400,000.00
View 9 Replies
View Related
Jan 7, 2008
Hi, I need to extract one record which has the most recent 'facilityprocessdate' from this following query. I'm a bit at a loss of how to do it since I need to keep all the other fields there as well.
SELECT a.WorkOrder, z.City, b.FacilityProcessDate, z.[State Abbreviation] AS State, a.MailTrackingID
FROM dbo.MailTracking AS a WITH (nolock) INNER JOIN
dbo.USPS_ConfirmData AS b WITH (nolock) ON SUBSTRING(a.PlanetCode, 1, 13) = b.PlanetCode AND SUBSTRING(a.PostNetCode, 1, 11)
= b.PostNetCode INNER JOIN
dbo.ZipCodeLookup AS z WITH (nolock) ON b.FacilityZipID = z.[ZIP Code]
WHERE (a.WorkOrder = '28696') AND (a.ClientApplicationID = '8') AND (SUBSTRING(a.PlanetCode, 1, 2) = '50') AND (a.RunDate >= GETDATE() - 90)
ORDER BY a.MailTrackingID, b.FacilityProcessDate
My results look like the following: So for example out of the first two records I'd need only the second one. MailTrackingID is the primary key.
WorkOrder City FacilityProcessDate State MailTrackingID
28696 PROVIDENCE 2007-11-07 23:01:28.000 RI 34313136
28696 CINCINNATI 2007-11-09 14:44:05.000 OH 34313136
28696 BELLMAWR 2007-10-22 21:40:43.000 NJ 34313141
28696 CINCINNATI 2007-10-23 23:42:13.000 OH 34313141
28696 BELLMAWR 2007-10-19 19:51:08.000 NJ 34313142
28696 CINCINNATI 2007-10-20 22:12:00.000 OH 34313142
View 8 Replies
View Related
Jun 19, 2012
Create a table with an Identity column, insert data / restart the server / insert more data / restart the server/ insert some more data.
My data looks like this :
Identity column
1
2
3
1002
1003
1004
1005
2002
2004
It looks like the indentity value gain +~1000 after most server restart (sometimes identity stay the same). This can be very dangerous for some datatype! The only thing google told me was this : URL...but microsoft did not comment on it yet!
View 9 Replies
View Related
Feb 13, 2014
The identity int column in my sql2012 db is not incrementing properly.
I have a table which uses an int auto identity as a primary key it is sporadically skipping increments, for example:
1, 2, 3, 4, 5, 1004, 1005
This is happening on a random number of tables at very random times...
View 5 Replies
View Related
Mar 25, 2014
I'm trying to find gaps in times in a table of sessions where the session endings aren't sequential. That is, session 1 can start at 10:00 and finish at 10:30, while session 2 started at 10:05 and finished at 10:45, and session 3 started at 10:06 and finished at 10:20. Only the starting times are in order; the ending times can be anywhere after that.Here's a bunch of sample data:
CREATE TABLE #SessionTest(SessionId int,Logindatetime datetime, Logoutdatetime datetime)
INSERT INTO #SessionTest
SELECT '1073675','Mar 3 2014 1:53PM','Mar 3 2014 1:53PM' UNION ALL
SELECT '1073676','Mar 3 2014 2:26PM','Mar 3 2014 3:51PM' UNION ALL
SELECT '1073677','Mar 3 2014 2:29PM','Mar 3 2014 3:54PM' UNION ALL
SELECT '1073678','Mar 3 2014 2:29PM','Mar 3 2014 5:47PM' UNION ALL
SELECT '1073679','Mar 3 2014 2:30PM','Mar 3 2014 3:37PM' UNION ALL
[code]....
View 6 Replies
View Related
Apr 24, 2008
Hi,
I have a SQL2005 db for tracking the prices of products at multiple retailers. The basic structure is, 'products' table lists individual products, 'retailer_products' table lists current prices of the products at multiple retailers, and 'price_history' table records when the price of a product changes at any retailer. The prices are checked from each retailer daily, but a row is added to the 'price_history' only when the price at the retailer changes.
Database create script:
http://www.boltfile.com/directdownload/db_create_script.sql
Full database backup:
http://www.boltfile.com/directdownload/database.bak
Database diagram:
http://www.boltfile.com/directdownload/diagram_0.pdf
I have the following query to retrieve the price history of a given product at multiple retailers:
SELECT
price_history.datetimeofchange, retailer.name, price_history.price
FROM
product, retailer, retailer_product, price_history
WHERE
product.id = 'b486ed47-4de4-417d-b77b-89819bc728cd'
AND
retailer_product.retailerid = retailer.id
AND
retailer_product.associatedproductid = product.id
AND
price_history.retailer_productid = retailer_product.id
This gives the following results:
2008-03-08 Example Retailer 22.3
2008-03-28 Example Retailer 11.8
2008-03-30 Example Retailer 22.1
2008-04-01 Example Retailer 11.43
2008-04-03 Example Retailer 11.4
The question(s) I have are how can I:
1 - Get the price of a product at a given retailer at a given date/time
For example, get the price of the product at Retailer 2 on 03/28/2008. Table only contains data for Retailer 1 for this date, the behaviour I want is when there is no data available for the query to find the last data at which there was data from that retailer, and use the price from that point - i.e. so for this example the query should result in 2.3 as the price, given that was the last recorded price change from that retailer (03/08/2008).
2 - Get the average price of a product at a given retailer at a given date/time
In this case we would need to perform (1) across all retailers, then average the results
I'd really appretiate anyone's help on this :)
many thanks in advance,
dg
View 17 Replies
View Related
Aug 23, 2007
I couldn't find a topic suitable for testing this, so I thought I'd start one.
Here is one way to get the islands without a tally table.declare@test table (symbol char(3), dt smalldatetime)
insert@test
select'abc','01/01/1990' union all
select'abc','01/02/1990' union all
select'abc','01/03/1990' union all
select'abc','01/04/1990' union all
select'abc','01/05/1990' union all
select'def','01/03/1990' union all
select'def','01/04/1990' union all
select'def','01/05/1990' union all
select'def','01/06/1990' union all
select'def','01/07/1990' union all
select'ghi','01/01/1990' union all
select'ghi','01/02/1990' union all
select'ghi','01/06/1990' union all
select'ghi','01/07/1990' union all
select'ghi','01/08/1990'
selectsymbol,
min(dt),
max(dt2)
from(
selectt1.symbol,
t1.dt,
t2.dt as dt2,
(select count(distinct t3.symbol) from @test as t3 where t3.symbol < t1.symbol and t3.dt <= t1.dt) AS r
from@test as t1
inner join@test as t2 on t2.symbol = t1.symbol
wheret2.dt - 1 = t1.dt
) as d
group bysymbol,
r
E 12°55'05.25"
N 56°04'39.16"
View 16 Replies
View Related
Feb 27, 2008
Hi all,
I have two tables - Planning and Appointments:
Planning - contains a list of planned items. Used to define boundaries for a work day and defines based on type what can be done for each item.
Id,
TypeId - the type of the planned items
BeginTime DateTime - begin date and time of the planned item
EndTime DateTime - end date and time for the planned item
In the Planning table we can have as many records per day as we need:
1, First Meeting, 1 Jan 2008 09:00, 1 Jan 2008 11:00
2, First Meeting, 1 Jan 2008 11:00, 1 Jan 2008 12:00
3, First Meeting, 1 Jan 2008 13:00, 1 Jan 2008 15:00
4, First Meeting, 1 Jan 2008 15:00, 1 Jan 2008 18:00
Appointments - contanis a list with appointments
Id,
BeginTime DateTime
EndTime DateTime
1, 1 Jan 2008 09:00, 1 Jan 2008 09:30
2, 1 Jan 2008 10:00, 1 Jan 2008 11:00
3, 1 Jan 2008 11:00, 1 Jan 2008 11:30
4, 1 Jan 2008 14:00, 1 Jan 2008 15:30
What is needed?
What I need is to a find a way to compare the planned items with the appointments and to return all the periods for which a planned time exists:
Free planned time:
1, 1 Jan 2008 09:30, 1 Jan 2008 10:00
2, 1 Jan 2008 11:30, 1 Jan 2008 12:00
3, 1 Jan 2008 13:00, 1 Jan 2008 14:00
4, 1 Jan 2008 15:30, 1 Jan 2008 18:00
So, having two multitudes of periods,where the one specifies the planning templates and the other real used time, I need to find all the periods which can be used for another appointments.
I've tried several aproaches, but I always faced performance problems.
Thanks in advance.
View 1 Replies
View Related
Aug 8, 2007
Hello, I have a report that looks fine in preview, but when put to PDF or printed contains gaps at the right and bottom.
Here is a picture of the problem: http://northeasttigers.webng.com/pdfproblem.jpg
My tables are the same width as the body, 15.5cm, and the report width is 21cm. Also adding the bottom table's top location attribute to it's height gives the same height as the body.
Any help much appreciated.
Greg
View 4 Replies
View Related
Jun 11, 2014
I have to find the records with in a paricular dates(from date and to date). In some cases @FromDate or @ToDate could be null. in the following query, when i am passing values @FromDate and @ToDate and execute the SP i am getting records which are not in the given range.
SELECT * FROM TABLE P WHERE
CONVERT(VARCHAR(10), P.[FromDate], 101) BETWEEN
CASE When @FromDate IS NULL Then CONVERT(VARCHAR(10),@minFromDate, 101)
ELSE CONVERT(VARCHAR(10), @FromDate, 101) END
AND CASE WHEN @ToDate IS NULL Then CONVERT(VARCHAR(10), @maxToDate, 101)
[Code] .....
View 4 Replies
View Related
Mar 15, 2006
Good Morning,I have a view that contains rate information, contractIDs, and effectivedates.I need to select the rate info based on contractID and date.I can provide a date and contractID, and I need to select the rate info forthat contract where the effective date is <= dateprovided.I need the 1 record that is closest to that date.I am thinking something with max() perhaps. Any ideas? The <= effectivedate will return several rows, I just need the one closest to the date Iprovide.Thanks for any advice,CK
View 2 Replies
View Related
Mar 24, 2008
how do you determine the date difference between the current record and the next record. i want to use the enddate on record 1 and calulate the time it took the next occurance to happen (start time) on record 2? and so forth.
View 1 Replies
View Related
Aug 31, 2014
I have a system log with NULL gaps between a sequence of numbers...see "BEFORE" sample below.
The number of gaps between the Sequence_ID's are arbitrary, but generally less then 50 records.
I'd like enumerate the gaps to produce the "AFTER" result, but do it with a single query or view, not through procedures.
I've been playing with windowed functions and groupings with no success. I'm guessing it'll need some recursive CTE logic, but I haven't been able to figure it out the correct loop.
BEFORE:
PK_IDSequence_ID
1035586935587
3035586234 NULL
8355585 NULL
1235584 NULL
4675583 35583
4035582 NULL
6035382 NULL
1435581 NULL
2035580 NULL
3435553 35563
6603589 NULL
9475559 35552
AFTER:
PK_IDSequence_ID
1035586935587
3035586234 3
8355585 2
1235584 1
4675583 35583
4035582 4
6035382 3
1435581 2
2035580 1
3435553 35563
6603589 1
9475559 35552
View 9 Replies
View Related
Mar 28, 2015
I need to populate a table with numbers with some gaps in between with logic below.
first row -1110
last row - 9550
1110
1120
1130
1140
1150
[Code] .....
View 8 Replies
View Related