Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

T-SQL Data Processing Expand / Collapse
Author
Message
Posted Saturday, June 21, 2008 11:12 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 9:36 AM
Points: 190, Visits: 442
Comments posted to this topic are about the item T-SQL Data Processing



PeteK
I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.
Post #521275
Posted Monday, June 23, 2008 7:15 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, November 17, 2014 12:50 PM
Points: 13,872, Visits: 9,598
I may be missing something here, but why use a While loop for this kind of thing? Do a set-based merge of all the update data, then upsert it into the master table. Two steps, very simple, very clean, no While loop.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #521747
Posted Monday, June 23, 2008 8:28 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 1:39 PM
Points: 775, Visits: 1,202
I don't like dedupe, let me tell you that :)

But I can't imagine how this WHILE loop would work on millions of rows of data comparison
I had issues with comparing between 400K records vs 8000 inserts using SET operations (still acceptable if I separate by country, etc..)

started looking to SSIS Fuzzy Matching and Fuzzy Lookup

Fuzzy Matching - It's pretty cool, dedupe within say the Master table without any T-SQL work, takes a while but it even gives confidence score

Fuzzy Lookup - I am still working on it, supposedly I can lookup those 8000 inserts in the 400K Master table


SQLServerNewbie

MCITP: Database Administrator SQL Server 2005
Post #521851
Posted Monday, June 23, 2008 9:33 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 9:36 AM
Points: 190, Visits: 442
I'm not a fan of dedup either, and didn't expect a harty round of approbation from this article...
I've found that you should ALWAYS consider your alternatives when it comes to SQL programming. Things frequently don't "work" as we think they "should".

I use this code to dedup databases of over 1 billion (yep, the B word) rows, a quarter of which (~250,000,000) are duplicates of some kind (exact or based on some "fuzzy" logic). One database processes in about 3 days, the other in about 18 hours (one has a larger record size than the other).

This represented a significant reduction in processing times for both these databases over the previous methodology written using a hybrid of external and internal (SQL w/cursors) coding; and its all done in SQL.

I am constantly looking for betterprocessing techniques that perform the required functions AND run quicker than existing procedures. So far, this is it.

As for SSIS, I will look into it, having not used it before.




PeteK
I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.
Post #521937
Posted Monday, June 23, 2008 7:36 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, March 6, 2014 6:13 PM
Points: 318, Visits: 1,183
Small suggestion: maybe I missed a reference to this, but wouldn't the Bit datatype be perfectly suited to the Data Source column (one bit column per source)? No need for explicit bitwise operations, acheives the same thing as you're doing against a TinyInt under the covers and the resulting code would be a little more human-readable...?

Regards,

Jacob
Post #522290
Posted Monday, June 23, 2008 11:19 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 9:36 AM
Points: 190, Visits: 442
This process was designed on a SQL 2000 system and ported to SQL 2005 with minimal changes. When I refactor it for SQL 2005 that would be the way to go.



PeteK
I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.
Post #522330
Posted Wednesday, June 25, 2008 9:16 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Sunday, September 18, 2011 6:11 PM
Points: 355, Visits: 299
Select
PartyId,
FirstName,
LastName,
Case when Source&1<>0 then 1 else 0 End[Source1],
Case when Source&2<>0 then 2 else 0 End[Source2],
Case when Source&4<>0 then 4 else 0 End[Source3],

AddDate,
ModDate
from dbo.ExistingMaster

Will you please let me know what Case when Source&1<>0 then 1 else 0 for in this code ?
Thx.
Post #523474
Posted Wednesday, June 25, 2008 10:22 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 9:36 AM
Points: 190, Visits: 442
Our current database represents data source as a TinyInt column containing bit values to indicate source type; 1=Source1, 2=Source2, 4=Source3, etc... where the decimal numbers 1, 2, & 4 represent binary bits 00000001, 00000010, 00000100, respectively.

In order to process these values within then constraints of SQL (SQL not having an aggregate OR function) I break the TinyInt into 3 separate columns Source1, Source2 & Source3 (as seen in the code). The 3 case statements, you've identified, serve this purpose.




PeteK
I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.
Post #523533
Posted Wednesday, June 25, 2008 12:01 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Sunday, September 18, 2011 6:11 PM
Points: 355, Visits: 299
Source is the column name. I still do not understand Source&1 or Source&2 here.
Post #523608
Posted Wednesday, June 25, 2008 2:03 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 9:36 AM
Points: 190, Visits: 442
Source is the name of a TinyInt column in the table.

Source&4<>0 is a method of determining a binary bit's value, in this case the 3rd bit from the right.

Source&4 is a boolean AND operaration using 4 as the mask, so if:

Source = 00000111 (decimal 7)
opcode = &
(mask) = 00000100 (decimal 4)
--------------------------------
yields 00000100

which is not equal to zero therefore the CASE statement would return 1.




PeteK
I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.
Post #523703
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse