Deriving Unique Rows From Historical Data

Oct 25, 2005

My application is to capture employee locations.

Whenever an employee arrives at a location (whether it is arriving for
work, or at one of the company's other sites) they scan the barcode on
their employee badge. This writes a record to the tblTSCollected table
(DDL and dummy data below).

The application needs to be able to display to staff in a control room
the CURRENT location of each employee.
[color=blue]
>From the data I've provided, this would be:[/color]

EMPLOYEE ID LOCATION CODE
963 VB002
964 VB003
966 VB003
968 VB004
977 VB001
982 VB001

Note that, for example, Employee 963 had formerly been at VB001 but was
more recently logged in at VB002, so therefore the application is not
concerned with the earlier record.

What would also be particularly useful would be the NUMBER of staff at
each location - viz.

LOCATION CODE NUM STAFF
VB001 2
VB002 1
VB003 2
VB004 1

Can anyone help?

Many thanks in advance

Edward

NOTES ON DDL:

THE BARCODE IS CAPTURED BECAUSE THE COMPANY MAY RE-USE BARCODE NUMBERS
(WHICH IS DERIVED FROM THE EMPLOYEE PIN), SO THEREFORE THE BARCODE
CANNOT BE RELIED UPON TO BE UNIQUE.

THE COLUMN fldRuleAppliedID IS NULL BECAUSE THAT PARTICULAR ROW HAS NOT
BEEN PROCESSED. THERE ARE BUSINESS RULES CONCERNING EMPLOYEE HOURS
WHICH OPERATE ON THIS DATA. ONCE A ROW HAS BEEN PROCESSED FOR
UPLOADING TO THE PAYROLL APPLICATION, THE fldRuleAppliedID COLUMN WILL
CONTAIN A VALUE. IN THE PRODUCTION SYSTEM, THEREFORE, ANY SQL AS
REQUESTED ABOVE WILL CONTAIN IN ITS WHERE CLAUSE (fldRuleAppliedID Is
NULL)

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[tblTSCollected]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[tblTSCollected]
GO

CREATE TABLE [dbo].[tblTSCollected] (
[fldCollectedID] [int] IDENTITY (1, 1) NOT NULL ,
[fldEmployeeID] [int] NULL ,
[fldLocationCode] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[fldTimeStamp] [datetime] NULL ,
[fldRuleAppliedID] [int] NULL ,
[fldBarCode] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (
963, 'VB001', '2005-10-18 11:59:27.383', 45480)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (
963, 'VB002', '2005-10-18 12:06:17.833', 45480)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (
964, 'VB001', '2005-10-18 12:56:20.690', 45481)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (964, 'VB002', '2005-10-18 15:30:35.117', 45481)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (964, 'VB003', '2005-10-18 16:05:05.880', 45481)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (966, 'VB001', '2005-10-18 11:52:28.307', 97678)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (966, 'VB002', '2005-10-18 13:59:34.807', 97678)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (966, 'VB001', '2005-10-18 14:04:55.820', 97678)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (966, 'VB003', '2005-10-18 16:10:01.943', 97678)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (968, 'VB001', '2005-10-18 11:59:34.307', 98374)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (968, 'VB002', '2005-10-18 12:04:56.037', 98374)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (968, 'VB004', '2005-10-18 12:10:02.723', 98374)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (977, 'VB001', '2005-10-18 12:05:06.630', 96879)
INSERT INTO dbo.tblTSCollected
(fldEmployeeID,
fldLocationCode,
fldTimeStamp,
fldBarCode)
VALUES (982, 'VB001', '2005-10-18 12:06:13.787', 96697)

View 4 Replies


ADVERTISEMENT

Delete Rows With Duplicate Column Data But Unique Row Data

May 25, 2000

Hello,

This probably has been addressed before but I was unable to get the search to work properly on this site.
I am needing a script/way of deleting all rows from a DB with the exception of one record left for each row that has duplicate column data. Example :
Row 1
Field1 = 12345 Field2 =xxxxx Field 3=yyyyy Field4=zzzzz etc.
Row 2
Field1 = 12345 Field2 =zzzzzz Field 3=xxxxxx Field4=yyyyyy etc.
Row3
Field1 = 12345 Field2 =20202 Field 3=11111 Field4=zzzzz etc.
Row 4
Field1 = 54321 Field2 =xxxxx Field 3=yyyyy Field4=zzzzz etc.
Etc. Etc.

I want to be able to find the duplicates for Field1 and then delete all but 1 of those rows.( I don't care which one I keep just so only one is left.) The data in the other fields may or may not be unique.

I know how to find the duplicates it's just the deleting part I am having problems with. Any help would be much appreciated. Thanks,

Kerry

View 3 Replies View Related

Unique Rows Of Data Query

Sep 21, 2006

How would I get the unique email addresses and its associated row of data from a SQL Server table that has no unique fields defined? If there is a duplicate email address then only show the first one and not the other rows with the same email address. Example table and data UserID             LastName        Email997249            MCCO-49       S.MCCO-49@SampleISD.org997462            BATE-62         A.BATE-62@SampleISD.org997605            DENS-05        B.DENS-05@SampleISD.org  997622            KAIS-22         A.KAIS-22@SampleISD.org997623            KAIS-22         A.KAIS-22@SampleISD.org997624            KAIS-22         A.KAIS-22@SampleISD.org997625            KAIS-22         A.ZKAIS-22@SampleISD.org997626            KAIS-22         AX.ZKAIS-22@SampleISD.org997627            KAIS-22         AX.KAIS-22@SampleISD.org   Result UserID             LastName        Email997249            MCCO-49       S.MCCO-49@SampleISD.org997462            BATE-62         A.BATE-62@SampleISD.org997605            DENS-05        B.DENS-05@SampleISD.org  997622            KAIS-22         A.KAIS-22@SampleISD.org997625            KAIS-22         A.ZKAIS-22@SampleISD.org997626            KAIS-22         AX.KAIS-22@SampleISD.org Thanks

View 13 Replies View Related

Historical Data

Sep 19, 2005

Hi Everyone.

I need some advise on how to create a historical database.

What is the best way of doing this? For example, should I create a new row if a column is changed in a row and Time Stamp all record? What happens when I have child tables link to a Header table?

I have been looking on the NET for methods of creating a historical database, but I cant find any.

Thanks in advance

View 11 Replies View Related

Historical Data

Oct 20, 2005

A general data design question:We have data which changes every week. We had considered seperatinghistorical records and current records into two different tables withthe same columns, but thought it might be simpler to have them alltogether in one table and just add a WeekID int column to indicatewhich week it represents (and perhaps an isCurrent bit column to makequerying easier). We have a number of tables like this, holding weeklydata, and we'll have to query for historical data often, but only backthrough the last year -- we have historical data going back to 1998 orso which we'll rarely if ever look at.Is the all-in-one-table approach better or the seperation of currentand historical data? Will there be a performance hit to organizing datathis way? I don't think the extra columns will make querying too muchmore awkward, but is there anything I'm overlooking in this?Thanks.

View 1 Replies View Related

Storing Historical Data?

Apr 7, 2008

From what I've read this is called 'slowly changing dimensions'. Bassically the system I'm working on needs to store the history of certain data so that at any time a user can look up an old project and view it exactly as is, even though the associated parts might have had certain changes over time.  From what I can tell Type 2 ( current and historical records are stored in the same table) seems to  be the most popular.  Type 4 (current records in one table and historical records in a seperate history table) seems like it would also work but I've been unable to find any articles comparing the two.  Does anybody have any info on the dis/advantages of one v.s. the other?

View 3 Replies View Related

Historical Data Problem

May 3, 2004

We have a database that adds over 100,000 records per day. This goes back to 2002 and I only need historical data for 6 months. Presently we can only can delete 1000 row at a time. Is there a faster way of deleting. We seem to continuely run out of disk space. Urgent!!!!!!!!!!!

View 7 Replies View Related

Historical Prices With Data Gaps

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

Historical Reporting On Changing Data

Apr 27, 2008

I've got a customer who wants reproducible/historical reporting. The problem is that the underlying data changes.

I tried to explain that this can't be done (can it?), but he doesn't
understand.

To illustrate the situation - Let's say a teacher wants to track
spelling test scores for her students.
The below are scores for students A, B, and C (for January, February, March)

A: {70,80,85}
B: {70,65, 80}
C: {100,90,100}

So, I can generate a historical report that charts the class average
and student trend - that's pretty easy.

Now, in April, we find that the school board has mandated that the
British spelling of words is ok, so now the cumulative scores (for
January, February, March, April)

A: {90,80,85,100}
B: {80,65, 80,80}
C: {100,90,100,75}

He wants a report showing the January average as (70+70+100)/3 = 80,
when really it is (90+80+100)/3 = 90.

Now imagine that there are actually thousands of data points changing like this...
Now also imagine that we add and remove students on a regular basis...

He and his office manager get frustrated when I explain that the
reports are not simple - in their mind it is. They have determined
the solution is to get a report writer and buy Crystal Reports...
I've tried to explain that the problem is that the report
specification is unclear (basically - they don't understand what they want). The situation is ok for now, I'm just trying to plan for when they figure out that buying Crystal Reports won't change their situation (except they are done several thousand dollars)...

Any tips?

View 20 Replies View Related

Searching Historical Data For Patterns

Feb 17, 2008



I have a database which contains time series data (historical stock prices) which I have to search for patterns on a day to day basis. But searching this historical data for patterns is very time consuming not only in writing the complex t-sql scripts but also executing them.

Table structure for one min data:
[Date] [Time] [Open] [High], [Low], [Close], [Adjusted_Close], [MA], [DI].....
Tick Data:
[Date] [Time] [Trade]
Most time consuming queries are with lots of inner joins. So for example if I have to compare first few mins data then I have to do inner join like:
With IntervalData AS
(
SELECT [Date], Sum(CASE WHEN 1430 = [Time] THEN [PriceRange] END) AS '1430',
Sum(CASE WHEN 1431 = [Time] THEN [PriceRange] END) AS '1431',
Sum(CASE WHEN 1432 = [Time] THEN [PriceRange] END) AS '1432'
FROM [INDU_1] GROUP BY [Date]
)
SELECT [Date] ,[1430], [1431], [1432], [1431] - [1430] As 'Range' from IntervalData
WHERE ([1430] > 0 AND [1431] < 0 AND [1432] < 0) OR ([1430] < 0 AND [1431] > 0 AND [1430] > 0)
------------------------------------------------------------------------
select ind1.[Time], ind1.PriceRange,ind2.[Time], ind2.PriceRange from INDU_1 ind1
INNER JOIN INDU_1 ind2 ON ind1.[Time] = ind2.[Time] - 1 AND ind1.[Date] = ind2.[Date]
where (ind1.[Time] = 2058) AND ((ind1.PriceRange > 0 AND ind2.PriceRange >0) OR (ind2.PriceRange < 0 AND ind1.PriceRange < 0))
ORDER BY ind1.[Date] DESC;
Is there anyway I can use Sql 2005 Data mining models to make this searching faster?

View 1 Replies View Related

Design For Storing And Querying Historical Data

Aug 2, 2007

I am working on a project, which involves displaying trends of certain aggregate values over time. For example, suppose we want to display how the number of active and inactive users changed over time.

One issue is how to store historical data. First of all, should I create a separate database for each historical snapshot or should I use one database for all snapshots? Second, our database size is a couple of gigabytes and replicating the entire database on a daily basis is not feasible. An alternative solution is to back up aggregate values, but how do I back up results of aggregate queries, where the user can specify a date range in the WHERE-clause? Another solution is to create fact tables from our relational schema and back those up.

Another issue is how to query historical data. Using multiple databases to store historical snapshots makes it harder to query.

As you can see there are several design alternatives and I would like to know how this sort of problem is generally solved in the industry. Does SQL Server provide any support for solving this problem?

Thanks.

View 5 Replies View Related

SQL Server 2012 :: How To Load Historical Data From Old System Into A New One

Aug 12, 2014

I want to load historical data from an old system into a new one.Thing is, that old system stored dates as Datetime and the new one uses DateTimeOffset.

All data was collected in the same Time Zone... but with the Daylight Saving Time (DST)

The offset is either +04:00 or +05:00, based on the calendar date. To add to the complexity, the rules for DST changed a couple of years ago.

To determine the offset, I'd need to know what was or would have been the server Timezone for each historical date.

View 1 Replies View Related

SQL Server 2014 :: Combine Data From Historical Table?

Aug 13, 2014

Recently, I partitioned one of my largest tables into multiple monthly field groups. For the current month, it is attached to my "Active' table. The older records are kept in the "historical" table. I need an efficient way to pull records when have a date range that can be spread across both tables.

View 9 Replies View Related

T-SQL (SS2K8) :: Obtaining Counts From Historical Data After Given Date

May 12, 2015

I'm looking to get counts on historical data where the number of records exists on or after May 1 in any given year. I've got the total number of records for each year worked out, but now looking for the number of records exist after a specific date. Here's what I have so far.

SELECT p.FY10,p.FY11,p.FY12,p.FY13,p.FY14,p.FY15
FROM
(
SELECT COUNT(recordID) AS S,
CASE DateFY

[code]...

View 2 Replies View Related

SQL Server 2014 :: Moving Old Data Out Into Newly Created Historical DB

Sep 29, 2015

I am getting ready to start a project where I am charged with moving out old data from production into a newly created historical DB. We have about 8 tables that are internal audit tables, that are big and full of old data. These tables are barely used and are taking up way too much space and time for maintenance.

I would like to create a way (SSIS?) to look at the date field in each of the 8 tables and copy out anything older than two years into my newly created history DB. Then deleting the older records from the source DB.

I don't know if SSIS is the best method to use. If it is, what containers to use to move over data, then how to do delete from source?

Can I do the mass deletes on my audit source tables without impacting performance/indexes/fragmentation?

View 5 Replies View Related

T-SQL (SS2K8) :: Historical Data Where Number Of Records Exists Between Two Dates With Different Years

Jul 10, 2015

Ok, I'm looking to get counts on historical data where the number of records exists between two dates with different years. The trick is the that the dates fall in different years. Ex: Give me the number of records that are dated between 0ct 1, 2013 and July 1, 2014.

A previous post of mine was similar where I needed to get records after a specific date. The solution provided for that one was the following. This let me get any records that occured after May 1 per given Fiscal year.

SELECT
MAX(CASE WHEN DateFY = 2010 THEN Yr_Count ELSE 0 END) AS [FY10],
MAX(CASE WHEN DateFY = 2010 THEN May_Count ELSE 0 END) AS [May+10],
MAX(CASE WHEN DateFY = 2011 THEN Yr_Count ELSE 0 END) AS [FY11],
MAX(CASE WHEN DateFY = 2011 THEN May_Count ELSE 0 END) AS [May+11],
MAX(CASE WHEN DateFY = 2012 THEN Yr_Count ELSE 0 END) AS [FY12],

[Code] ....

I basically need to have CASE WHEN MONTH(OccuranceDate) between Oct 1 (beginning year) and July 1 (ending year).

View 4 Replies View Related

Deriving The Colunm

Nov 13, 2007



Hello All

I want to creat a colunm from two colunms in a specific format

COL1 COL2 COL3
123456 01-10-2007 12070001 ( 12: From First two digit of Col1, 07 from the year of colunm2 and 0001: if combination 1207 is first else increment)
125647 01-11-2005 12050001
126756 12-25-2007 12070002 (* here since combination of 1207 is repeating it gets increment to 0002)

Can somebody help me please

View 8 Replies View Related

Getting Unique Rows

Jun 15, 2004

Is it possible to use the DISTINCT clause on just one field in the SELECT statement?

The following SQL statement causes an error:

SELECT DISTINCT appt.ref, appt.notes FROM Appointments appt

...because DISTINCT can't be used on the notes field as it of type 'text'.

How can I focus the DISTINCT keyword on just the ref field?

(I know ref is the primary key, so this example wouldn't need the DISTINCT keyword, but I've simplified a much more complex statement)


Paul

View 6 Replies View Related

Duplicate Key But Unique Rows.

Jan 25, 2000

I have a large table that consists of the columns zip, state, city, county. The primary key "zip" has duplicates but the rows are unique.
How do I filter out only the duplicate zips.
Randy Garland

View 2 Replies View Related

How To Get Unique Combination Of Rows

Jun 18, 2004

Hi,
Following is my table:Bets

BetId GameID

500 108
500 109

501 108
501 109
501 110

502 108
502 109

I want BetId 500 and 502 to be returned as result if i give select
criteria where game id = 108,109.
Pls.Note: It should not return BetId 501 in the result, since it belongs to different combination(108,109,110).
Similarly if i give, select criteria where game id =(108,109,110) it should return
BetId 501.not the 500 and 502..which is different combination..

Hope i clarified my problem..pls help me in this regard.Thanks a lot...

View 2 Replies View Related

Getting Unique Rows From The Resultset

Nov 15, 2006

Hi,

I am trying to do a join which involves more than 3 tables. One is a parent table and the other two table have 1:n relationship with that parent table.

But duplicate records are being returned in the resultset. How do I eliminate duplicate records?

This is my query.

SELECT table1.* from table1 left outer join table2 on table1.id=table2.id
left outer join table3 on table1.id=table3.id

I tried doing DISTINCT here but with no success.

SQL with distinct clause.

SELECT distinct table1.id, table1.* from table1 left outer join table2 on table1.id=table2.id
left outer join table3 on table1.id=table3.id

This is the error I get:
The text data type cannot be selected as DISTINCT because it is not comparable

Please help.

View 4 Replies View Related

Retrieving Unique Rows

Jun 3, 2008

I have the following sql:

SELECT DISTINCT patient.patientID, patientFirstName, patientLastName, patientDOB, patientGender, completed_date
FROM patient
LEFT JOIN patient_record ON patient_record.patientID = patient.patientID
WHERE (sub_categoryID = 4 OR patient_record.allocated = 4)
AND (patient_status = 1 OR patient_status = 2 OR patient_status = 5)
GROUP BY patient.patientID, patientFirstName, patientLastName, patientDOB, patientGender, completed_date

This brings up duplicate records, my aim is to bring distinct records, now if I take out the other returned fields after patientID
and using the following sql:

SELECT DISTINCT patient.patientID
FROM patient
LEFT JOIN patient_record ON patient_record.patientID = patient.patientID
WHERE (sub_categoryID = 4 OR patient_record.allocated = 4)
AND (patient_status = 1 OR patient_status = 2 OR patient_status = 5)
GROUP BY patient.patientID

This bring up distinct results, but I need to retrieve the other fields from the database i.e. patientFirstName and patientLastName

Please can you help.

View 2 Replies View Related

Deriving From A Column Date Type Into Format YyyyMMddhhmm

Nov 21, 2007

hi,

i have to derive a column from an existing column in my data source with a data type of DATE.
to illustrate my point lets assume that:

i have dt00 as my current column with its data type of date and now i have to create another column dt01 with data type int.
i need to format the date from dt00 to the following format yyyyMMddhhmm, where


yyyy - year
MM- moth in two digits (e.g: 03, 12)
dd - days in two digits (e.g: 03, 12)
hh - hours in two digits (e.g: 03, 12)
mm - minutes in two digits (e.g: 03, 12)

and allocate this value to this new column dt01.

could someone give me some clue on how to do this using the SCRIPT TASK?


many thanks,


nicolas

View 6 Replies View Related

SSIS Deriving Dt_str To Dt_dbtimestamp Including Milliseconds

Dec 27, 2007

Hi, I am trying to derive a column from:

mm/dd/yyyy hh:mms.fff to dt_dbtimestamp as:

(dt_dbtimestamp)(colum_name,1, 23) when I include the period and three digits for milliseconds the package fails if I leave it out it is successfull. I need to include milliseconds for my datawarehouse project. I tried many different ways and always with failure
01/23/2007 12:23:15.234 is the date(example) derived: (dt_dbtimestamp)(column_name,1,23) fails
01/23/2007 12:23:15.234 is the date(example) derived: (dt_dbtimestamp)(column_name,1,19) succeeds

Thanks

View 9 Replies View Related

How Do I Get Unique Rows Based On StudentID

Oct 4, 2006

I am a beginner at SQL so thanks ahead of time.....How do I get unique rows based on studentID? Distinct and group by don't seem to workDESIRED RESULTSStudentID  First Name Last Name  Other Columns...............................................634565491 MARINA    BALDERAZ 640484566 TERE        BALDERAZCURRENT SQL AND RESULTS.....SELECT ClassRosterRecID, StudentDataRecID, StudentDataKey, StudentID, FirstName, LastName, CurrentGrade, Gender, Ethnicity, EconDisadvantaged, TitleI, Migrant, LEP, Bilingual, ESL, SpecialEducation, GiftedTalented, AtRisk, CareerTech, Dyslexia, LastName + ', ' + FirstName AS LastNameFirstName, EconDisadvantagedSort, TitleISort, MigrantSort, LEPSort, BilingualSort, ESLSort, SpecialEducationSort, GiftedTalentedSort, AtRiskSort, CareerTechSort, DyslexiaSort, DistrictID, CampusID FROM vClassDemographicsDetail WHERE (DistrictID = '057910') AND (CampusID = '057910101') AND (LastName LIKE '%BALDERAZ%')StudentID  First Name Last Name  Other Columns...............................................634565491 MARINA    BALDERAZ 634565491 MARINA    BALDERAZ 634565491 MARINA    BALDERAZ 640484566 TERE        BALDERAZ640484566 TERE        BALDERAZ640484566 TERE        BALDERAZ

View 1 Replies View Related

Selecting Unique Rows In A Join

Mar 20, 2008

I got the following query:SELECT TOP (8) ext.extID, ext.Quote, ext.sourceTitle, ext.extRating, gf_game.gameID, gf_game.catID, gf_game.URL, gf_game.TitleFROM         gf_game_ext AS ext INNER JOIN                      gf_game ON gf_game.gameID = ext.gameIDWHERE     (ext.Approved = 1)ORDER BY ext.extID DESC which is e.g. producing this output: 6000 -some text- Title 90 1960 2 tom-cl tom cl5999 -some text- title 90 1960 2 tom-clcl asdf5998 -some text- title 90 1959 2 tom-cl-cl asdfWhat I'd like to do now is to filter out the duplicate GameIDs (= 1960) so that just one unique row with the gameid 1960 is remaining. If I put in a SELECT DINSTINCT TOP(8) it just counts for the table ext, but I need it to count for gf_game.gameID - is that possible?Thanks a lot! 

View 9 Replies View Related

Select Unique Rows For All Columns

May 17, 2007

Using DISTINCT with SELECT have effect only for one column.
But when is needed to select (or to count) queries for all rows for all columns in a table without duplicates, doesn't work.

Select DISTINCT a1,a2,a3,a4 From Y ---> results 167 rows
Select DISTINCT a4 From Y ---> " 85 rows

Any thoughts?


Jorge3921

View 14 Replies View Related

Count Unique Rows In Each Field

Jul 24, 2013

I have a table in Access 2007 that has about 30 field names and I want to have a count of how many unique rows there are in each field. I want to have these results put into another table that will just have the field name and then the count of how many unique rows there are.

I have code in VBA that will loop through my SQL and change out the field name, but I can't seem to get the SQL right before I can start looping it. For just one field name this would be what I have to count the unique names...

So far I have this:

INSERT INTO newtable
COUNT(*) FROM (SELECT Raw_Table.FieldName, COUNT(Raw_Table.FieldName) AS CountOfFieldName
FROM Raw_Table
GROUP BY Raw_Table.FieldName);

And its not going too well.

View 1 Replies View Related

Selecting & Then Inserting Unique Rows

Sep 18, 2007

As a beginner i am having trouble with this.
i have two different tables , both have a name column, nvarchar datatype.
I would like to select from table B all the rows which contain a name which is not in table A.
Then insert these rows, into table A

tried a few different ways & just keep getting strange errors that refer to courier font ??

SQL Team Your my Hero !

View 11 Replies View Related

Insert Unique Rows In Temp Table

Nov 3, 2006

i have temp table name "#TempResult" with column names Memberid,Month,Year. Consider this temp table alredy has some rows from previuos query.  I have one more table name "Rebate" which also has columns MemberID,Month, Year and some more columns. Now i wanted to insert rows from "Rebate" Table into Temp Table where MemberID.Month and Year DOES NOT exist in Temp table.
MemberID + Month + Year should ne unique in Temp table

View 1 Replies View Related

Selecting The Rows Based Off Of Unique Columns

Mar 18, 2007

Hi there, im still learning SQL so thanks in advance.I have a table with columns of customer's information, [customerID], [customerFirst], [customerLast], , [program] ... other columns ...  There will be entries where there can be duplicate customerFirst and customerLast names.  I would like to just return a single entry of the duplicate names and all associated row information.  IE: [customerID], [customerFirst], [customerLast],            [ email],             [program]         01               Bill                 Smith             bill.smith@hotmail.com    ymca        02               Bill                 Smith             bill.smith@hotmail.com    Sports        03               jon                   doe                 jon.doe@hotmail.com    AAA        04               jon                   doe                 jon.doe@hotmail.com    Ebay          05               Paul                 Sprite             paul.sprite@hotmail.com    Rec Desired Returned result:        01               Bill                 Smith             bill.smith@hotmail.com    ymca        03               jon                   doe                 jon.doe@hotmail.com    AAA
         05               Paul                 Sprite             paul.sprite@hotmail.com    Rec So in my code i have this:dAdapter = new SqlDataAdapter("SELECT * FROM [Poc_" + suffix + "] WHERE (SELECT DISTINCT [CustomerLastName], [CustomerFirstName], [CustomerEmail] FROM [Poc_" + suffix + "])", cnStr);         dAdapter.Fill(pocDS, "Data Set");        However this is throwing up an error when i build the app:  An expression of non-boolean type specified in a context where a condition is expected, near ')'.



Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException:
An expression of non-boolean type specified in a context where a
condition is expected, near ')'.

Source Error:




Line 52: //dAdapter = new SqlDataAdapter("SELECT DISTINCT * FROM [Poc_" + suffix + "] ORDER BY [CustomerLastName]", cnStr); Line 53: dAdapter = new SqlDataAdapter("SELECT * FROM [Poc_" + suffix + "] WHERE (SELECT DISTINCT [CustomerLastName], [CustomerFirstName], [CustomerEmail] FROM [Poc_" + suffix + "])", cnStr); Line 54: dAdapter.Fill(pocDS, "Data Set");Line 55: Line 56: //Dataset for name comparison  1: Can someone explain to me why this error is happening?2: Can soemone confirm that my intentions are correct with my code?3: If I'm completely off, can someone steer me in the right direction?Thanks alot!-Terry  

View 12 Replies View Related

Delete Duplicate Rows With No Unique Columns

Apr 3, 2000

I have 4 rows which are exactly the same. I want to delete one row but i do not have any unique identifing columns. How should i delete that row ?

View 1 Replies View Related

Unique Index Returns Duplicate Rows

Oct 25, 2004

We are running the following query, which has a unique index on Table_2 (col1 and sys1), and Column col1 from Table_1 is unique.

select top 100 s.*, x.col1
from Table_1 s
left outer join Table_2 x
on x.col1 = s.col1 and x.sys1 = 'SYSTEM0'

Unfortunately this query returns duplicate rows. And every time the result is different

But once we dbcc dbreindex the unique index on Table_2, the result will not have any dups.

Any ideas?

Thanks

Steve

View 1 Replies View Related







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