Selecting Top Record In A Group?

Mar 18, 2015

I’m writing a document management system. The documents themselves are created from the contents of a database. The database is SQL Server.

The database contains a table, like so:

ClientID, ProjectID, DocumentID, MinorVersion, MajorVersion, Name

Initially, the user will create a “V0.1” document. So the data would look something like

ClientID = 1
ProjectID = 1
DocumentID = 1
MajorVersion = 0
MinorVersion = 1
Name = “My Document”

Thereafter, the user can create new versions as “0.2”, “0.3”, etc., or “1.0”, “1.1”, “2.0”, etc.

For example, a “2.1” document would be stored as:

ClientID = 1
ProjectID = 1
DocumentID = 1
MajorVersion = 2
MinorVersion = 1
Name = “My Document”

The earlier versions will still exist on the database, but the latest version will be 2.1.

There may be several different documents, with different DocumentID’s (e.g. DocumentID = “1”, DocumentID = “2”), etc., and each of these documents may have many versions.

I’m trying to write a query to display a list of documents showing ClientID, ProjectID, DocumentID, MinorVersion, MajorVersion, Name… but the list should only display the latest version of each document.

So, if the database contained the following records:

ClientID, ProjectID, DocumentID, MajorVersion, MinorVersion, Name
1,1,1,0,1,My Document
1,1,1,0,2,My Document
1,1,1,0,3,My Document
1,1,1,1,0,My Document
1,1,1,2,0,My Document
1,1,1,2,1,My Document
1,1,2,0,1,My Second Document
1,1,2,0,2,My Second Document
1,1,2,0,3,My Second Document

My query should return:

ClientID, ProjectID, DocumentID, MajorVersion, MinorVersion, Name
1,1,1,2,1,My Document
1,1,2,0,3,My Document

… where 2.1 is the latest version of Document 1 and 0.3 is the latest version of Document 2.how to do it.

View 4 Replies


ADVERTISEMENT

T-SQL Problem...selecting TOP 1 Of Each GROUP In GROUP BY?

Jul 23, 2005

Hi,I was hoping someone may be able to help me with a tricky T-SQLproblem.I need to come up with a SELECT statement that does basically thefollowing:Select RCRD_REFNO, MAX(MODIF_DTTM) as MODIF_DTTM from[StageDb].[dbo].tblPersonInfo group by RCRD_REFNOHowever, I need to select ONLY the TOP 1 of each group (i.e. only 1record for each unique RCRD_REFNO). The problem is of course that if Iadd 'top 1' after select, it only brings back 1 record full stop,rather than 1 for each group!Now, I have previously come up with a similar query that DOES do thissuccessfully, but it relies on a criteria (such as a unique identifier)-unfortunately, the nature of the table I'm using for this currentjob means that it actually doesn't have a primary key, as it'ssimply a staging area for raw data, and can even have completelyidentical records in it. I think the only way I'm going to be able todo it is to literally use the 'TOP' command somehow, but am notsure how to adapt the above to implement it...I'd be very gratefulfor any advice.Many thanks

View 6 Replies View Related

Selecting First Row From GROUP BY

Jul 20, 2005

Hi,I having problems returning only the first row of data for each GROUPfor the query below. Can someone please help? Thanks.SELECT bid, xact_date, xact_timeFROM badge_history bhGROUP BY bid, xact_date, xact_timeORDER BY bid, xact_date DESC, xact_time DESCSo if the data returned by the above query is:bid xact_date xact_time-------------------------------------------------0000000025697510200212051118220000000025697510200212051118160000000025697510200212051118101517440346432003012211324415174403464320030117165815151744034643200301171657571517440346432003011716573915174403464320030117165727Then I need the new query to produce:bid xact_date xact_time-------------------------------------------------00000000256975102002120511182215174403464320030122113244Can anyone suggest anything that might work!? Thanks again.

View 2 Replies View Related

Selecting Record

Sep 4, 2007

Hi i was wanting to know how to select a record in a gridview. I have a gridview with firsname and lastname. I currently have select command on it but don't want it. I want to be able to select first name or last name and have it take me to that record on the database.  

View 3 Replies View Related

Selecting Next And Previous Record

Jun 25, 2004

I'm trying to add a next and previous button to a popup window I have on a photo gallery -

Having trouble with the sql

I know I would have 2 select statements that would each return 1 result set.

I know how to get the top ( and bottom by ordering descending and doing Select Top 1)

But how would I get the next one up!

I would hate returning the entire image section and perform the calcuation in the business tier :(

View 4 Replies View Related

Selecting The First Record In A Join?

Mar 1, 2012

I have one table like this:

Code:
CREATE TABLE DlIndexTable
(SessionStartTime DATETIME NOT NULL PRIMARY KEY, SchemaID INTEGER NOT NULL,
DLBaseRate REAL NOT NULL)

and one like so:

Code:
CREATE TABLE DlTextDataTable (
SessionStartTime DATETIME NOT NULL REFERENCES DlIndexTable,
ChTimestamp FLOAT NOT NULL, Channel01data VARCHAR (255),
Channel02data VARCHAR (255), ... , Channel16data VARCHAR (255),
CONSTRAINT TxtDatPriKey PRIMARY KEY (SessionStartTime, ChTimestamp))

I want to get some combined data from both tables, so right now I am joining them at the SessionStartTime column, which is a primary key in the first and a foreign key in the second table, something like this:

Code:
SELECT DlIndexTable.SessionStartTime, DlTextDataTable.Channel01data
FROM DlIndexTable
LEFT JOIN DlTextDataTable
ON DlIndexTable.SessionStartTime = DlTextDataTable.SessionStartTime
WHERE DlIndexTable.SessionStartTime BETWEEN '2006-10-13 16:40:08.790' AND '2012-03-01 17:54:30.930'
ORDER BY DlIndexTable.SessionStartTime, DlTextDataTable.ChTimestamp

The trouble is that this query, exactly as requested, gives me all the entries from the second table matching the first, while I really would like to pick just one row (preferably, the first chronologically - by ChTimestamp) so that the first column (SessionStartTime) has distinct entries in the resulting table. What would be the simplest way of doing that? Performance is not a big priority over simplicity since the first table could have only a few hundred rows (maybe a couple of thousand), while the second will be real tiny.

View 10 Replies View Related

Selecting Most Recent Record

Jul 20, 2005

MSSQL2000I have a table that contains customer transactionsCustomerIDTransactionTransactionDate....I need to select the most recent record that matches a specific CustomerID.I am fairly new to SQL, could someone provide a sample select statement.TIATim Morrison-- Tim Morrison--------------------------------------------------------------------------------Vehicle Web Studio - The easiest way to create and maintain your vehicle related website.http://www.vehiclewebstudio.com

View 3 Replies View Related

Selecting Unique Record

Jul 20, 2005

I have a stored procedure (below), that is supposeto get a Reg Number from a table, (Reg_Number), insuch a way that every time the stored procedure is called,it will get a different reg number, even if the storedprocedure is called simultaneously from two differentplaces,However it is not working that way.If two different users access a function in thereVB program at the same time, the two different userswill get the same reg number.I have looked at the stored procedure, it looks foolproof,yet it is not working that way.Thanks in Advance,Laurence NuttallProgrammer Analyst IIIUCLA - Division of Continuing Education'---------------------------------------------------------------------------Here it is:CREATE PROCEDURE sp_GetNextRegNum@newRegNum char(6) = NULL OUTPUTASLABEL_GET_ANOTHER_REG:Select @newRegNum =(select min(Reg) from reg_number)IF Exists (select Reg from reg_number where reg = @newRegNum )BeginDelete from reg_number where reg = @newRegNumIF @@Error <> 0BeginGoto LABEL_GET_ANOTHER_REGEnd--EndifEndELSEGoTo LABEL_GET_ANOTHER_REG--EndifGO

View 6 Replies View Related

Selecting Correct Record

Mar 26, 2008



This is my first post so I hope I'm doing it to the right forum. I need to compare a LastUpdated time to Start and End Time fields to get the "Due" Time for a given order. Can someone give me the correct SQL? (the example below should result in 6:00:00 AM "Due" time.) All are DATETIME fields. Thank you.

LastUpdated StartTime EndTime DueTime
5/29/2007 12:04:32 AM 2:00:00 AM 11:30:00 AM 3:30:00 PM
11:30:00 AM 5:00:00 PM 9:00:00 PM 5:00:00 PM 2:00:00 AM 6:00:00 AM

View 15 Replies View Related

Selecting Distinct Data Using Group By

Aug 4, 2013

I have an action log table which records when a registrant record was viewed by a compnay employee. I have an sql query like this:

SELECT [ID]
,[RegistrantID]
,[EmployeeID]
,[UserID]
,[CompanyID]

[Code] ....

and data is like this:

IDRegistrantID EmployeeIDUserID CompanyID VacancyID Action ActionDate
17931629515163213NULL 42013-08-04 16:45:40.457
17921629215163213NULL 42013-08-04 16:45:33.003
1791NULL15163213NULL 32013-08-04 16:45:23.660
1790162959162893NULL 42013-08-04 16:45:09.543

[Code] ....

I want to select distinct views to a registrantid record ( the first ones) in one year. if a registrant was viewed 10 tmes a year then it will show only first time it was viewed. If it was viewed 10 times by an employeed in 2 years then it will show first time it was viewed. if it was viewed by 2 employees of same company 10 times in one year then it first time viewed record will be shown. if it was seen 10 times by 2 employees of two different companies in one year then first record of two companies will be shown. do i need to use group by or what ?

View 1 Replies View Related

SELECTing Random Record From TABLE?

Apr 24, 2001

Hello.
I need to select a random record from TABLE. It might look easy with using RAND() function, but the tricky part is that ID's which are the PRIMARY KEY, were assigned as a random number.
So right now ID's in that TABLE look some thing like that: -18745, 45809, 129, -5890023, 487910943, -209, etc...
If any one have any ideas please respond.
Thanks in advance.

View 2 Replies View Related

Insert Record Selecting Then To A First Table

May 19, 2004

Hi all,

I Have the following situation:

CREATE TABLE First_Table (id INTEGER IDENTITY(1,1) NOT NULL,
titre VARCHAR(50) NOT NULL,
annee INTEGER NOT NULL,
idMES INTEGER,
genre VARCHAR(20) NOT NULL,
resume TEXT,
codePays VARCHAR(4),
CONSTRAINT PKFilm PRIMARY KEY (idFilm),
FOREIGN KEY (idMES) REFERENCES Artiste,
FOREIGN KEY (codePays) REFERENCES Pays);

I'ld like fill in this tables records inserting in the column id values I got in the one other table. In Oracle it is possible to do it using sourceTable.nextval where sourceTable is created as: CREATE SEQUENCE sourceTable;
How can I do it in MS SQL or Transact-sql?

Thanx all

View 8 Replies View Related

Selecting Only Earliest Record - Query Help

May 25, 2005

I'm no SQL whizz yet but I'm learning hard, and need to get some information from our DB rather urgently so have resorted to this fantastic forum, only I can't find what I'm looking for.

Basically I'm selecting a whole load of entries that have a (admission)date field after 2001, but I only want to return the Earliest (admission) for each (patients number).

Here is the script I have created to select all the data, but how can I limit the results to just the earliest (admission date) for each (patient).


SELECT
Admission_Year, Admission_Month, Age_On_Admission, [Length of stay(continuing)], [Patient's Number], [Cons epis seq no], Sex, [Main Primary Pas Diag], [Date of Death], [Epi duration], [OP Code1], [Admission date], [Date of Death] - [Admission date] AS [days before death],[Intended Management]
FROM dbo.Admissions
WHERE (Admission_Year > 2001) AND (Age_On_Admission > '64') AND ([Intended Management] = 'inpatient') AND ([Date of Death] IS NULL)


I would really appreciate it if anyone can help with this, I'm sorry I can't really contribute to this forum as an SQL expert as .net is really my forte and I usually spend my time contributing to the asp.net forums. :)

View 1 Replies View Related

Selecting The First Instance Of Each Record From A Subset

May 21, 2001

Hi

I'm sure this is an easy problem but my brain is fried today...however how do I do the following:


I have a two column table. One is a key field where duplicates can arise and the other is a datetime field. So you might have some records looking like this:

1231999-06-14 12:17:11.000
1231999-06-14 12:17:31.310
1231999-06-14 12:17:31.000
1231999-06-14 12:22:56.000
1231999-06-14 12:22:58.000
8901999-06-15 10:00:18.000
8901999-06-15 10:03:30.340
8901999-06-15 10:03:30.000
8901999-06-15 10:03:40.000

OK, how do I get the top 1 of each key so that I get a subset of records looking like the following:
1231999-06-14 12:17:11.000
8901999-06-15 10:00:18.000


Thanks in advance


Bazza

View 1 Replies View Related

Help Selecting Duplicate Record Details

Oct 10, 2006

I have the following query I am using to identify duplicate records in one of my database tables:


Code:


SELECT memberID,
COUNT(memberID) AS NumOccurrences
FROM ChapterMembers
GROUP BY memberID
HAVING ( COUNT(memberID) > 1 )



Executing the above proc returns 4079 records...

Now, I would also like to know the ChapterID for each member with a duplicate record. ChapterID is also stored in the ChapterMembers Table...

I tried running the following procedure:


Code:

SELECT memberID,
COUNT(memberID) AS NumOccurrences, chapterID
FROM ChapterMembers
GROUP BY memberID, chapterID
HAVING ( COUNT(memberID) > 1 )



But zero results are returned ...

The ultimate goal here is to identify duplicate records where one of their chapterID's = '81017' and to delete that record from the database.

Anyone have any ideas what I am doing wrong? Also, any suggestions for removing the records would be appreciated.

Thanks,

Jandrews

View 3 Replies View Related

T-SQL (SS2K8) :: Selecting The Top Record With Certain Conditions?

May 14, 2014

The situation is that we have resources (trucks) that perform shifts. Shifts consists of actions. A resource can perform multiple shifts.

For every resource we want to find the record that:

- Is 'younger' than the last realized action.

- Has actionkind pickup, deliver or clean

I have constructed a solution with CTE and row_number but I was curious if there would be other alternatives. The fact that I'm joining a CTE onto itself and subject the outcome to a partition makes me think there are sharper ways.

Note that the action id in the data below is also sorted but in practice this need not be the case. The sorting key is prevalent.

output of the query is

id_action id_resource actionKindCode
4665 4 clean
34540 96 pickup
24000 901 clean
declare @mytable table (
id_action int,
id_shift int,

[code]....

View 6 Replies View Related

Selecting A Record By Part Of The TIMESTAMP

Apr 20, 2007

Hi,

Is it possible to select a record by just the date part of the data type TIMESTAMP?

date_time
2007-04-20 16:27:01

For example, a query to select all records added today.

Thanks very much,

dai.hop

View 2 Replies View Related

Selecting Only The Last Record In Joined Table

Oct 10, 2005

Hello everyone, I have a query problem.I'll put it like this. There is a 'publishers' table, and there is a'titles' table. Publishers publish titles (of course). Now I want to make aquery (in MS SQL Server) that would return the last title published by everyof the publishers. Quite clear situation. But I can't make it work.If I use inner join (which I should, because I need data from both tables)then I get a result showing all publishers and all titles. What I want toget is all publishers, and only their last title, so I don't have more thanone line for the same publisher, and this line should contain publisherdetails and last title details.I tried using DISTINCT, but it works on a whole resultant row rather then acolumn, and since rows are all distnict (because they also contain columnsfrom titles) this didn't help me.What I can do is (in my application) first get a list of publishers, andthen loop through them selecting only the last title belonging to eachpublisher. I want to see if there is a way to accomplish the same thing withan SQL query (or maybe a stored procedure, view, or whatever). Anything ispossible, as long as it stays within SQL server and doesn't rely on theclient application.Of course, both 'publishers' and 'titles' tables have a primary key('publisherID', and 'titleID'), and 'titles' has a 'publisherID' columnwhich relates titles with publishers.Help :)

View 4 Replies View Related

Help Selecting The Proper Child Record

Mar 23, 2006

Good Morning,I have a person table with personID. I have a personRate table withpersonID, rateID, and effectiveDate.I need to select fields from personRate, but I want the fields from theproper record.I need the one child record that has the most current date of the largestrateID.For example a person may have many rate records. I need the record that hasthe most current date of the largest rateID they have. Does that makesense?I am making a view that has data from both tables. I need to display themost current rate info.Any ideas? TIA ~ CK

View 4 Replies View Related

QUERY HELP: Selecting Distinct For Two Columns Group By One

Jul 23, 2005

Greetings.I'm having a little trouble with a query. The idea is simple I need todisplay a list of recently unique visited URLs and the last time Ivisited.I have 2 table one stores the user and time/date and another has theURL.So all I need is the URL (no duplicates) and the last visit.Below is the SQL to create the tables and data to help with the query.Thank you for your help.CREATE TABLE [stat_hits] ([hit_id] [int] (1, 1) NOT NULL ,[hit_date] [datetime] NOT NULL CONSTRAINT [DF_stat_hits_hit_date]DEFAULT (getdate()),[user_id] [varchar] (12) NOT NULL ,[hit_ip] [varchar] (15) NOT NULL ,[shp_id] [int] NOT NULL ,CONSTRAINT [PK_stat_hits] PRIMARY KEY CLUSTERED([hit_id]) ON [PRIMARY]) ON [PRIMARY]GOCREATE TABLE [stat_hit_pages] ([shp_id] [int] (1, 1) NOT NULL ,[shp_url] [varchar] (1000) NULL ,[shp_count] [int] NULL ,CONSTRAINT [PK_stat_hit_pages] PRIMARY KEY CLUSTERED([shp_id]) ON [PRIMARY]) ON [PRIMARY]GOINSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37878,'2005-06-01 16:07:35','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37877,'2005-06-01 16:07:13','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37876,'2005-06-01 15:41:17','ADMIN','0.0.0.0',7339)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37875,'2005-06-01 15:41:03','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37874,'2005-06-01 15:20:31','ADMIN','0.0.0.0',7330)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37873,'2005-06-01 15:20:28','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37872,'2005-06-01 14:45:46','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37871,'2005-06-01 14:35:51','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37870,'2005-06-01 14:30:25','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37869,'2005-06-01 14:28:28','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37868,'2005-06-01 14:28:23','ADMIN','0.0.0.0',7325)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37867,'2005-06-01 14:28:17','ADMIN','0.0.0.0',7322)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37866,'2005-06-01 14:28:15','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37861,'2005-06-01 14:27:09','ADMIN','0.0.0.0',7339)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37860,'2005-06-01 14:27:05','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37859,'2005-06-01 14:26:59','ADMIN','0.0.0.0',7322)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37858,'2005-06-01 14:26:58','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37853,'2005-06-01 14:25:59','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37852,'2005-06-01 14:23:51','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37851,'2005-06-01 13:58:49','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37850,'2005-06-01 13:44:06','ADMIN','0.0.0.0',7330)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37849,'2005-06-01 13:44:04','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37848,'2005-06-01 13:44:04','ADMIN','0.0.0.0',7340)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37847,'2005-06-01 13:43:58','ADMIN','0.0.0.0',7330)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37846,'2005-06-01 13:43:53','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37845,'2005-06-01 13:26:29','ADMIN','0.0.0.0',7325)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37844,'2005-06-01 13:22:34','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37843,'2005-06-01 13:22:29','ADMIN','0.0.0.0',7325)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37842,'2005-06-01 13:21:15','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37841,'2005-06-01 13:19:17','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37840,'2005-06-01 13:17:20','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37839,'2005-06-01 13:17:20','ADMIN','0.0.0.0',7320)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37838,'2005-06-01 11:55:15','ADMIN','0.0.0.0',7339)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37837,'2005-06-01 11:55:09','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37836,'2005-06-01 11:53:08','ADMIN','0.0.0.0',7338)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37835,'2005-06-01 11:53:01','ADMIN','0.0.0.0',7325)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37834,'2005-06-01 11:34:34','ADMIN','0.0.0.0',7337)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37833,'2005-06-01 11:34:24','ADMIN','0.0.0.0',7336)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37832,'2005-06-01 11:02:59','ADMIN','0.0.0.0',7335)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37831,'2005-06-01 11:02:53','ADMIN','0.0.0.0',7334)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37830,'2005-06-01 11:02:46','ADMIN','0.0.0.0',7324)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37829,'2005-06-01 11:02:40','ADMIN','0.0.0.0',7333)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37828,'2005-06-01 11:02:31','ADMIN','0.0.0.0',7332)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37827,'2005-06-01 11:02:25','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37826,'2005-06-01 11:02:21','ADMIN','0.0.0.0',7331)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37825,'2005-06-01 11:02:12','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37824,'2005-06-01 11:01:23','ADMIN','0.0.0.0',7330)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37823,'2005-06-01 11:01:21','ADMIN','0.0.0.0',7328)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37822,'2005-06-01 11:01:20','ADMIN','0.0.0.0',7327)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37821,'2005-06-01 10:58:23','ADMIN','0.0.0.0',7330)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37820,'2005-06-01 10:58:10','ADMIN','0.0.0.0',7328)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37819,'2005-06-01 10:58:09','ADMIN','0.0.0.0',7327)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37818,'2005-06-01 10:55:27','ADMIN','0.0.0.0',7326)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37817,'2005-06-01 10:55:23','ADMIN','0.0.0.0',7325)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37816,'2005-06-01 10:55:17','ADMIN','0.0.0.0',7322)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37815,'2005-06-01 10:55:16','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37810,'2005-06-01 10:54:20','ADMIN','0.0.0.0',7330)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37809,'2005-06-01 10:54:12','ADMIN','0.0.0.0',7329)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37808,'2005-06-01 10:51:30','ADMIN','0.0.0.0',7328)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37807,'2005-06-01 10:51:29','ADMIN','0.0.0.0',7327)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37806,'2005-06-01 10:51:10','ADMIN','0.0.0.0',7328)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37805,'2005-06-01 10:51:09','ADMIN','0.0.0.0',7327)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37804,'2005-06-01 10:35:46','ADMIN','0.0.0.0',7326)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37803,'2005-06-01 10:35:41','ADMIN','0.0.0.0',7325)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37802,'2005-06-01 10:35:29','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37801,'2005-06-01 10:35:21','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37800,'2005-06-01 10:35:20','ADMIN','0.0.0.0',7320)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37799,'2005-06-01 10:33:58','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37798,'2005-06-01 10:33:50','ADMIN','0.0.0.0',7328)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37797,'2005-06-01 10:33:50','ADMIN','0.0.0.0',7327)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37796,'2005-06-01 10:33:09','ADMIN','0.0.0.0',7326)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37795,'2005-06-01 10:33:05','ADMIN','0.0.0.0',7325)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37794,'2005-06-01 10:32:45','ADMIN','0.0.0.0',7324)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37793,'2005-06-01 10:32:18','ADMIN','0.0.0.0',7323)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37792,'2005-06-01 10:31:47','ADMIN','0.0.0.0',7322)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37791,'2005-06-01 10:31:31','ADMIN','0.0.0.0',7321)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37790,'2005-06-01 10:31:31','ADMIN','0.0.0.0',7320)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37789,'2005-06-01 10:30:04','ADMIN','0.0.0.0',7320)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37788,'2005-05-31 20:49:56','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37787,'2005-05-31 20:49:54','ADMIN','0.0.0.0',5942)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37786,'2005-05-31 20:49:54','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37785,'2005-05-31 20:49:02','ADMIN','0.0.0.0',5942)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37784,'2005-05-31 20:48:54','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37783,'2005-05-31 20:48:53','ADMIN','0.0.0.0',5942)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37782,'2005-05-31 20:48:52','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37781,'2005-05-31 20:48:41','ADMIN','0.0.0.0',5941)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37780,'2005-05-31 20:48:37','ADMIN','0.0.0.0',215)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37779,'2005-05-31 20:48:30','ADMIN','0.0.0.0',4)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37775,'2005-05-31 20:46:44','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37774,'2005-05-31 20:46:40','ADMIN','0.0.0.0',7319)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37773,'2005-05-31 20:46:39','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37772,'2005-05-31 20:46:12','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37771,'2005-05-31 20:46:09','ADMIN','0.0.0.0',7319)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37770,'2005-05-31 20:46:08','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37769,'2005-05-31 20:45:55','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37768,'2005-05-31 20:45:52','ADMIN','0.0.0.0',7319)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37767,'2005-05-31 20:45:51','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37766,'2005-05-31 20:45:33','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37765,'2005-05-31 20:45:29','ADMIN','0.0.0.0',7319)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37764,'2005-05-31 20:45:29','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37763,'2005-05-31 20:45:28','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37762,'2005-05-31 20:44:52','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37761,'2005-05-31 20:44:48','ADMIN','0.0.0.0',7319)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37760,'2005-05-31 20:44:47','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37759,'2005-05-31 20:44:23','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37758,'2005-05-31 20:44:18','ADMIN','0.0.0.0',7319)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37757,'2005-05-31 20:44:18','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37756,'2005-05-31 20:43:50','ADMIN','0.0.0.0',6258)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37755,'2005-05-31 20:43:41','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37754,'2005-05-31 20:43:37','ADMIN','0.0.0.0',7318)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37753,'2005-05-31 20:43:36','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37752,'2005-05-31 20:43:31','ADMIN','0.0.0.0',7317)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37751,'2005-05-31 20:43:16','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37750,'2005-05-31 20:43:10','ADMIN','0.0.0.0',6684)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37749,'2005-05-31 20:43:10','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37748,'2005-05-31 20:40:04','ADMIN','0.0.0.0',7318)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37747,'2005-05-31 20:40:00','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37746,'2005-05-31 20:39:52','ADMIN','0.0.0.0',7317)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37745,'2005-05-31 20:39:24','ADMIN','0.0.0.0',7316)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37744,'2005-05-31 20:39:23','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37743,'2005-05-31 20:35:56','ADMIN','0.0.0.0',7315)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37742,'2005-05-31 20:35:43','ADMIN','0.0.0.0',7311)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37741,'2005-05-31 20:34:17','ADMIN','0.0.0.0',7314)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37740,'2005-05-31 20:34:17','ADMIN','0.0.0.0',1449)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37739,'2005-05-31 20:34:01','ADMIN','0.0.0.0',7313)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37738,'2005-05-31 20:33:54','ADMIN','0.0.0.0',7312)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37737,'2005-05-31 20:12:57','ADMIN','0.0.0.0',6681)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37736,'2005-05-31 20:09:40','ADMIN','0.0.0.0',6681)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37735,'2005-05-31 20:09:33','ADMIN','0.0.0.0',6258)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37734,'2005-05-31 20:09:03','ADMIN','0.0.0.0',6681)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37733,'2005-05-31 20:08:49','ADMIN','0.0.0.0',7289)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37732,'2005-05-31 20:08:44','ADMIN','0.0.0.0',6254)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37731,'2005-05-31 20:08:42','ADMIN','0.0.0.0',3443)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37730,'2005-05-31 20:08:40','ADMIN','0.0.0.0',7282)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37729,'2005-05-31 20:08:32','ADMIN','0.0.0.0',5983)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37728,'2005-05-31 20:08:24','ADMIN','0.0.0.0',6960)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37727,'2005-05-31 20:08:22','ADMIN','0.0.0.0',5918)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37726,'2005-05-31 20:08:18','ADMIN','0.0.0.0',25)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37725,'2005-05-31 20:08:15','ADMIN','0.0.0.0',5740)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37724,'2005-05-31 20:08:11','ADMIN','0.0.0.0',4)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37723,'2005-05-31 20:08:09','ADMIN','0.0.0.0',3)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37720,'2005-05-31 20:08:03','ADMIN','0.0.0.0',4)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37617,'2005-05-31 18:51:08','ADMIN','0.0.0.0',7290)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37615,'2005-05-31 18:51:00','ADMIN','0.0.0.0',7289)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37598,'2005-05-31 18:48:08','ADMIN','0.0.0.0',7282)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37597,'2005-05-31 18:48:04','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37596,'2005-05-31 18:48:03','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37595,'2005-05-31 18:47:21','ADMIN','0.0.0.0',7282)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37594,'2005-05-31 18:47:12','ADMIN','0.0.0.0',6960)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37593,'2005-05-31 18:47:09','ADMIN','0.0.0.0',5918)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37592,'2005-05-31 18:47:02','ADMIN','0.0.0.0',5740)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37590,'2005-05-31 18:46:59','ADMIN','0.0.0.0',6587)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37583,'2005-05-31 18:46:40','ADMIN','0.0.0.0',9)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37582,'2005-05-31 18:46:31','ADMIN','0.0.0.0',1691)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37580,'2005-05-31 18:46:18','ADMIN','0.0.0.0',9)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37576,'2005-05-31 18:46:04','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37575,'2005-05-31 18:46:02','ADMIN','0.0.0.0',5942)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37574,'2005-05-31 18:46:01','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37569,'2005-05-31 18:45:24','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37568,'2005-05-31 18:45:16','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37567,'2005-05-31 18:45:16','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37563,'2005-05-31 18:44:07','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37562,'2005-05-31 18:44:05','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37561,'2005-05-31 18:44:04','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37545,'2005-05-31 18:40:30','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37544,'2005-05-31 18:40:30','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37543,'2005-05-31 18:40:12','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37536,'2005-05-31 18:34:19','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37535,'2005-05-31 18:34:15','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37534,'2005-05-31 18:34:14','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37532,'2005-05-31 18:27:02','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37531,'2005-05-31 18:27:00','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37530,'2005-05-31 18:27:00','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37518,'2005-05-31 18:00:34','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37517,'2005-05-31 18:00:31','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37516,'2005-05-31 18:00:31','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37515,'2005-05-31 17:59:41','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37514,'2005-05-31 17:59:37','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37513,'2005-05-31 17:59:37','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37512,'2005-05-31 17:59:01','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37511,'2005-05-31 17:58:58','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37510,'2005-05-31 17:58:57','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37509,'2005-05-31 17:56:16','ADMIN','0.0.0.0',6610)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37508,'2005-05-31 17:56:07','ADMIN','0.0.0.0',6989)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37507,'2005-05-31 17:56:01','ADMIN','0.0.0.0',6610)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37506,'2005-05-31 17:55:56','ADMIN','0.0.0.0',7271)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37505,'2005-05-31 17:55:52','ADMIN','0.0.0.0',7199)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37504,'2005-05-31 17:55:43','ADMIN','0.0.0.0',7271)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37503,'2005-05-31 17:55:41','ADMIN','0.0.0.0',7199)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37502,'2005-05-31 17:53:57','ADMIN','0.0.0.0',7269)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37501,'2005-05-31 17:53:44','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37500,'2005-05-31 17:53:40','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37499,'2005-05-31 17:53:40','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37498,'2005-05-31 17:52:18','ADMIN','0.0.0.0',7269)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37497,'2005-05-31 17:52:06','ADMIN','0.0.0.0',7271)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37496,'2005-05-31 17:51:28','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37495,'2005-05-31 17:51:22','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37494,'2005-05-31 17:51:22','ADMIN','0.0.0.0',31)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37493,'2005-05-31 17:51:01','ADMIN','0.0.0.0',6979)INSERT INTO [stat_hits]([hit_id],[hit_date],[user_id],[hit_ip],[shp_id]) VALUES(37492,'2005-05-31 17:50:57','ADMIN','0.0.0.0',6103)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(3,'/scripts/iMenu.asp?_Ref=450493&_XID=40000000&ParentID=',2245)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(4,'/scripts/objects/MyZBF.asp?_XID=19999900&_Ref=450493&_Ref2=',2917)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7329,'/scripts/objects/list.asp?_XID=70000005&_Ref=1398186089&_reset=true&_table=2002000&|MenuID=40000000',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7330,'/scripts/objects/edit.asp?_XID=70000005&_Ref=1398186089&_table=2002000&_item=ADAMDOUG',5)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7331,'/scripts/objects/edit.asp?_XID=70000028&_Ref=1398186089&_table=1002009&_item=225000000',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7332,'/scripts/objects/edit.asp?_XID=70000028&_Ref=1398186089&_table=1002009&_item=215000000',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7333,'/scripts/objects/list.asp?_XID=70000028&_Ref=1398186089&_table=1002009&',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7334,'/scripts/objects/list.asp?_XID=70000028&_Ref=1398186089&_table=1001000&_parenturl=1',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7335,'/scripts/objects/edit.asp?_XID=70000028&_Ref=1398186089&_table=1001000&_item=1002009&_parenturl=1',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7336,'/scripts/objects/edit.asp?_XID=70000028&_Ref=1398186089&_table=1001054&_item=1000006&_parenturl=3',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7337,'/scripts/objects/edit.asp?_xid=70000028&_ref=1398186089&_table=1001054&&_parenturl=3',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7338,'/scripts/objects/navigator.asp?_xid=70000030&_ref=1398186089',12)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7339,'/scripts/objects/navigator.asp?_xid=70000028&_ref=1398186089',2)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7340,'/scripts/iKnow.asp?_ref=1398186089&_deep=http%3A//ZBFw2kdev01/scripts/objects/edit.asp%3F_XID%3D70000005%26_Ref%3D1398186089%26_ table%3D2002000%26_item%3DADAMDOUG',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(9,'/scripts/objects/list.asp?_XID=70000052&_Ref=450493&_reset=true&_table=215000001&|MenuID=40000000',1532)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(25,'/scripts/objects/list.asp?_XID=70000028&_Ref=450493&_reset=true&_table=1002009&|MenuID=40000000',144)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(31,'/scripts/objects/save.asp?',3986)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(215,'/scripts/objects/list.asp?_XID=70000030&_Ref=450493&_reset=true&_table=3001062&|MenuID=40000000',138)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(1449,'/scripts/objects/mappings.asp?',17)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(1691,'/scripts/objects/edit.asp?_XID=70000052&_Ref=450493&_table=215000001&_item=11',26)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(3443,'/scripts/objects/list.asp?_XID=70000028&_Ref=450493&_table=1001000&_parenturl=2',16)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(5740,'/scripts/objects/consolemaster.asp?_XID=80000003&_Ref=450493&_reset=true&showall=false&page_id=215000002&|MenuID=40000000',177)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(5918,'/scripts/objects/consolemaster.asp?_XID=80000003&_Ref=450493&showall=false&mode=listitself&item=215000006&page_id=215000002',15)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(5941,'/scripts/objects/edit.asp?_XID=70000030&_Ref=450493&_table=3001062&_item=12',9)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(5942,'/scripts/objects/edit.asp?_XID=70000030&_Ref=450493&_table=3001062&_item=12&_formtab=&process=&step=&elem=',62)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(5983,'/scripts/objects/edit.asp?_XID=70000028&_Ref=450493&_table=1002009&_item=225000000',15)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6103,'/scripts/objects/edit.asp?_XID=70000028&_Ref=450493&_table=1001002&_parenturl=3&_item=215000018&_formtab=&process=&step=&elem=',21)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6254,'/scripts/objects/edit.asp?_XID=70000028&_Ref=450493&_table=1001000&_item=225000001&_parenturl=2',4)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6258,'/scripts/objects/edit.asp?_XID=70000028&_Ref=450493&_table=1001000&_item=225000001&_parenturl=2&',4)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6587,'/scripts/objects/consolemaster.asp?_XID=80000004&_Ref=450493&_reset=true&showall=false&page_id=215000003&|MenuID=40000000',81)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6610,'/scripts/objects/consolemaster.asp?_XID=80000004&_Ref=450493&showall=false&page_id=215000003',88)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6681,'/scripts/objects/edit.asp?_XID=70000028&_Ref=450493&_table=1001054&_item=225000175&_parenturl=4',3)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6684,'/scripts/objects/edit.asp?_XID=70000028&_Ref=450493&_table=1001054&_parenturl=4&_item=225000175&_formtab=&process=&step=&elem=',7)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6960,'/scripts/objects/edit.asp?_XID=80000003&_Ref=450493&_table=215000001&_item=68',3)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6979,'/scripts/objects/edit.asp?_XID=70000052&_Ref=450493&_table=215000001&_item=161&process=215000001&step=215000003&elem=215000018',25)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(6989,'/scripts/objects/consolemaster.asp?_XID=80000004&_Ref=450493&showall=false&mode=drill&item=215000120&drill_id=215000005&page_id=215000003&group=1&desc=BTFG',54)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7199,'/scripts/objects/consolemaster.asp?_XID=80000004&_Ref=450493&showall=false&page_id=215000006',24)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7269,'/scripts/objects/consolemaster.asp?_XID=80000004&_Ref=450493&showall=false&page_id=215000010',3)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7271,'/scripts/objects/consolemaster.asp?_XID=80000004&_Ref=450493&showall=false&mode=listitself&item=215000200&page_id=215000006&group=1&desc=Operations%20Executive',3)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7282,'/scripts/objects/edit.asp?_XID=80000003&_Ref=450493&_table=215000001&_item=68&process=215000001&step=215000003&elem=215000018',2)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7289,'/scripts/objects/edit.asp?_xid=80000003&_ref=450493&_table=225000001&_item=75&_parenturl=1',1)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7290,'/scripts/objects/edit.asp?_xid=80000003&_ref=450493&_table=215000016&_item=86&_parenturl=1',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7311,'/scripts/objects/edit.asp?_XID=80000003&_Ref=450493&_table=225000001&_item=75',11)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7312,'/scripts/objects/showpopup.asp?_XID=80000003&_Ref=450493&_table=225000001&_item=75&destable=225000001&_mode=mappings&_seed=72528.66',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7313,'/scripts/objects/mappings.asp?_XID=80000003&_Ref=450493&_table=225000001&_item=75&destable=225000001&_mode=mappings&_seed=72528.66&_popup=true',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7314,'/scripts/objects/edit.asp?_XID=80000003&_Ref=450493&_table=225000001&_item=90&process=&step=&elem=',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7315,'/scripts/objects/edit.asp?_xid=80000003&_ref=450493&_table=225000001&_item=90',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7316,'/scripts/objects/edit.asp?_xid=80000003&_ref=450493&_table=225000001&_item=90&_formtab=0&process=&step=&elem=',0)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7317,'/scripts/objects/edit.asp?_xid=80000003&_ref=450493&_table=215000016&_item=86',1)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7318,'/scripts/objects/edit.asp?_xid=80000003&_ref=450493&_table=215000016&_item=86&_formtab=&process=&step=&elem=',1)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7319,'/scripts/objects/edit.asp?_XID=70000028&_Ref=450493&_table=1001000&_parenturl=2&_item=225000001&_formtab=&process=&step=&elem=',5)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7320,'/scripts/iknow.asp?_Ref=1398186089',6)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7321,'/scripts/iMenu.asp?_Ref=1398186089&_XID=40000000&ParentID=',10)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7322,'/scripts/objects/MyZBF.asp?_XID=19999900&_Ref=1398186089&_Ref2=',9)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7323,'/scripts/objects/list.asp?_XID=70000028&_Ref=1398186089&_reset=true&_table=1002009&|MenuID=40000000',8)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7324,'/scripts/objects/edit.asp?_XID=70000028&_Ref=1398186089&_table=1002009&_item=1000001',1)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7325,'/scripts/objects/list.asp?_XID=70000030&_Ref=1398186089&_reset=true&_table=3001062&|MenuID=40000000',6)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7326,'/scripts/objects/edit.asp?_XID=70000030&_Ref=1398186089&_table=3001062&_item=12',2)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7327,'/scripts/objects/save.asp?',4)INSERT INTO [stat_hit_pages] ([shp_id],[shp_url],[shp_count]) VALUES(7328,'/scripts/objects/edit.asp?_XID=70000030&_Ref=1398186089&_table=3001062&_item=12&_formtab=&process=&step=&elem=',4)

View 2 Replies View Related

T-SQL (SS2K8) :: Selecting Latest Record With Info

Aug 27, 2014

I have created the following SQL snippet that is a very simple mock-up illustrating the problem (I hope!) that I am facing:

-- create table
if object_id('tempdb..#tmpdelnotes') is not null
drop table #tmpdelnotes

create table #tmpdelnotes(
DelNote int identity (1,1) ,
DelDate date not null,
Item int not null,
Customer int not null)

[code]...

What I need to retrieve is a unique list of item numbers with information about the latest (DelDate) delivery note. The "Clumsy workaround" works, but is not very pretty when doing multiple table joins. Is it really necessary to use a derived table for this kind of query? Window functions can only exist in the SELECT and ORDER BY clauses, which is understandable since the calculations take place (I would guess) after the aggregations in the HAVING clause.

View 2 Replies View Related

Selecting Only 1 Record Based On Multiple Criteria

Jan 31, 2014

I have inherited a query which currently returns multiple instances of each work order because of the joined tables. The code is here and I've detailed the criteria needed below but need the best way to accomplish this:

Select h.worknumber, h.itemcode, h.descr, h.task_descr, h.qty, h.itemised,
h.serialnum, h.manufacturer, h.model_id, h.depot, h.date_in, h.date_approved,
h.est_complete_date, h.actual_complete_date, h.meterstart, h.meterstop,
h.custnum, h.name cust_name, h.addr1, h.addr2, h.town, h.county, h.postcode,
h.country_id, h.contact, h.sitename, h.siteaddr1, h.siteaddr2, h.sitetown,

[Code] ....

Each work order should only be returned once, and with the following additional criteria:

1. i.meter - this should return only the lowest number from that file.

2. sm.next_calendar_date - this should return only the most recent date out of those selected for the certificates on this piece of equipment

3. wh.meterstop as [Last Service Hours],
wh.date_created as [Last Service] - this should return the number from wh.meterstop at the most recent wh.date_created for that piece of equipment.

View 1 Replies View Related

Selecting TOP X Child Records For A Parent Record

Oct 29, 2006

Hi,I have a stored procedure that has to extract the child records forparticular parent records.The issue is that in some cases I do not want to extract all the childrecords only a certain number of them.Firstly I identify all the parent records that have the requird numberof child records and insert them into the result table.insert into t_AuditQualifiedNumberExtractDetails(BatchNumber,EntryRecordID,LN,AdditionalQualCritPassed)(select t1.BatchNumber,t1.EntryRecordID,t1.LN,t1.AdditionalQualCritPassedfrom(select BatchNumber,RecordType,EntryRecordID,LN,AdditionalQualCritPassedfrom t_AuditQualifiedNumberExtractDetails_Temp) as t1inner join(select BatchNumber,RecordType,EntryRecordID,Count(*) as AssignedNumbers,max(TotalNumbers) as TotalNumbersfrom t_AuditQualifiedNumberExtractDetails_Tempgroup by BatchNumber, RecordType, EntryRecordIDhaving count(*) = max(TotalNumbers)) as t2on t1.BatchNumber = t2.BatchNumberand t1.RecordType = t2.RecordTypeand t1.EntryRecordID = t2.EntryRecordID)then insert the remaining records into a temp table where the number ofrecords required does not equal the total number of child records, andthenloop through each record manipulating the ROWNUMBER to only selectthe number of child records needed.insert into @t_QualificationMismatchedAllocs([BatchNumber],[RecordType],[EntryRecordID],[AssignedNumbers],[TotalNumbers])(select BatchNumber,RecordType,EntryRecordID,Count(*) as AssignedNumbers,max(TotalNumbers) as TotalNumbersfrom t_AuditQualifiedNumberExtractDetails_Tempgroup by BatchNumber, RecordType, EntryRecordIDhaving count(*) <max(TotalNumbers))SELECT @QualificationMismatched_RowCnt = 1SELECT @MaxQualificationMismatched = (select count(*) from@t_QualificationMismatchedAllocs)while @QualificationMismatched_RowCnt <= @MaxQualificationMismatchedbegin--## Get Prize Draw to extract numbers forselect @RecordType = RecordType,@EntryRecordID = EntryRecordID,@AssignedNumbers = AssignedNumbers,@TotalNumbers = TotalNumbersfrom @t_QualificationMismatchedAllocswhere QualMismatchedAllocsRowNum = @QualificationMismatched_RowCntSET ROWCOUNT @TotalNumbersinsert into t_AuditQualifiedNumberExtractDetails(BatchNumber,EntryRecordID,LN,AdditionalQualCritPassed)(select BatchNumber,EntryRecordID,LN,AdditionalQualCritPassedfrom t_AuditQualifiedNumberExtractDetails_Tempwhere RecordType = @RecordTypeand EntryRecordID = @EntryRecordID)SET @QualificationMismatched_RowCnt =QualificationMismatched_RowCnt + 1SET ROWCOUNT 0endIs there a better methodology for doing this .....Is the use of a table variable here incorrect ?Should I be using a temporary table or indexed table if there are alarge number of parent records where the child records required doesnot match the total number of child records ?

View 2 Replies View Related

Selecting A Top Record Based On A Datestamp Field

Jan 30, 2008



This is a simple one, and I know that it has to be fairly common, but I just can't figure out an elegant way to do it. I have a table with the following fields:
OrderID (FK, not unique)
InstallationDate (Datetime)
CreateDtTm (Datetime)

There is no PK or Unique ID on this table, though an combo of OrderID and CreateDtTm would ostensibly be a unique identifier.

For each OrderID, I need to pull the InstallationDate that was created most recently (based on CreateDtTm). Here's what I've got so far, and it works, but man is it ugly:



SELECT a.OrderID, InstallationDate

FROM ScheduleDateLog a

INNER JOIN

(SELECT OrderID, max(convert(varchar(10),CreateDtTm,102)+'||' +convert(varchar(10), InstallationDate,102)) as TopRecord

FROM ScheduleDateLog GROUP BY OrderID) as b

ON convert(varchar(10),CreateDtTm,102)+'||' +convert(varchar(10), InstallationDate,102)=b.TopRecord

AND a.OrderID = b.OrderID

View 8 Replies View Related

SQL Server 2012 :: Selecting Unique Record From A Table

Feb 10, 2014

I have a table (Billing Table) having multiple records for people having one record per person per each month.

How to get a list of the guys having record just for one month (say feb) and doesn't have any other months.

View 4 Replies View Related

SQL Server 2014 :: Missing One Record When Selecting By Date Range

May 26, 2015

When I run this query:

SELECT orderno, *
FROM _order
WHERE order_date >= '5/14/2015 00:00:00'
AND order_date < '5/15/2015 11:59:59'
ORDER BY order_date asc

I get a result of:

A1G7222015-05-14 13:00:11.143
A1G7232015-05-14 13:33:35.407
A1G7242015-05-14 13:39:16.657
A1G7252015-05-14 14:25:43.507
A1G7262015-05-14 14:29:18.050
A1G7272015-05-14 15:38:12.263

But I know there is one more record that falls into 05/15/2015

A1G7282015-05-15 12:26:52.807

Can you see what I am missing in my query in order for me to retrieve the missing record A1G728?

View 9 Replies View Related

SQL Server 2014 :: Selecting And Merging Records For Singular Complete Record

Jan 24, 2015

I have a database full of different types of leads some for company A some for company B and so on, each doing a different service. However the leads from B can be used for A and leads from A can be used for B, so I want to merge the data.

Example:

Phone Number Name Home Owner Credit Insurance
727-555-1234 Dave Thomas Yes B
727-555-1234 Dave Thomas Gieco

I would like the end result to be one record:

Phone Number Name Home Owner Credit Insurance
727-555-1234 Dave Thomas Yes B Gieco

Since these were imported into SQL they all have a unique ID, here are the current labels

ID,phone_ number,first_ name,last_name,address1, address2, address3,city,state,postal_code,HOME_OWNR,HH_INCOME,CREDIT_RATING,AGE,MATCH,source_id,
title,comments,dnc_flag,provider,vehicle,coverage,alt_phone,email,marital status,dob

View 8 Replies View Related

Getting First Record Of Each Group

May 21, 2002

Is there a way to do this.

If I have a sorting which gives me multiples of column C1 but which can be uniquely identified by C1+C2+C3, and I want to query for the first C1 in each of C1's unique values, how would I go about doing that?

View 1 Replies View Related

Group Min Record

Sep 16, 2004

Hello Guyz,

A small problem here, I have the below table and I need to group and display the record that has the minimum value in the table (this table is derived from a query that permutates some records to give me this result).

F1 F2 F3
QQQ C 2
QQQ B 1
QQQ A 3

expected result:
QQQ B 1

my result:
when I group by F1, First(F2) and MIN(F3):
QQQ C 1

when I group by F1, MIN(F2) and MIN(F3):
QQQ A 1

when I group by F1, F2 and MIN(F3):
QQQ C 2
QQQ B 1
QQQ A 3

Any help would be very much appreciated..


Cyherus

View 1 Replies View Related

Getting Group-by By Record Value In Second Row?

Dec 14, 2014

I have following query

Select Date, Item_Code, SUM(In_Quantity) as In_Quantity, SUM(Issue_Quantity) as Issue_Quantity, (SUM(In_Quantity)-SUM(issue_Quantity)) as BalanceQty from

(
select tbl_add_product.Date as Date, tbl_add_product.Item_Code, tbl_add_product.In_Quantity, 0 as Issue_Quantity from tbl_add_product
where Item_Code = 'pen'
union ALL
select tbl_issue_product.Date as Date, tbl_issue_product.Item_Code, 0 as In_Quantity, Issue_Quantity from tbl_issue_product
where Item_Code = 'pen'
)
X group by Item_Code, Date

which gives following result:

**Date Item_Code In_Quantity Issue_Quanitity BalanceQty**
2014-12-02 pen 100 0 100
2014-12-03 pen 50 50 0

I want to 100 in second row. the logic is that balance Qty from first row should be added to In_Qty so that when Issue_Quantity is subtracted from it, it gives BalanceQty

View 1 Replies View Related

How Can I Get The First Record Of Each Group

Feb 19, 2006

Master,
How can I get the first record of each group which I had selected by "Group by".I try it but failed.3ks

"USE pubs
SELECT top 1 *
FROM titles
GROUP BY type
ORDER BY price"

View 2 Replies View Related

Last Record In Each Group

Feb 28, 2007

Greetings anyone -

I have been attempting to figure out - in Report Builder - how to print only the last record in each group, i.e. the last activity. I see no Last function available anywhere.

Would someone please be so kind as to advise how this can be done?

If this cannot be accomplished in Rpt Builder, it looks as if the Last function is available within Report Designer. Unfortunately, although documentation states it's available, it does not state where this function can be utilized. I'm certainly having no luck.

Help pls?

Tks & B/R

View 1 Replies View Related

Select Last Record By Group?

May 18, 2012

query to show last record/Partner or PartnerName.

select 'PURCHASE' as EntityName, d.PartnerName, h.*
from (
select MAX([TimeStamp]) [Data import], COUNT(1) [Numar de inregistrari], StartDate, EndDate, DistributorId
from DataImport.PurchaseHistory
group by DistributorId, StartDate, EndDate
) h
inner join Partner d on d.PartnerId = h.DistributorId
where d.Active = 1
order by DistributorId, StartDate desc, EndDate desc

View 4 Replies View Related







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