SQL Server 2005 Express Import/Export Functionality

SQL 2005 Express is a great little server from Microsoft that allows you to run a slimmed down version of SQL Server 2005 for free. You can even use it to host websites, and as long as your individual databases don't run over 4GB of storage, and you don't care about using more than 2GB of RAM, it might be the perfect candidate for your environment.

The reason Microsoft did this is to fight back against the free products from other vendors. Other alternatives include PostgreSQL, MySQL, Oracle Lite among others. With the release of this free Express edition of SQL Server, Microsoft aims to get people to use SQL Server, and keep customers from flocking to open source alternatives. Once they have you locked it, they are hoping that at some point you will either need the tools or features that are offered by the SQL Server 2005 Standard or that you will hit the 4GB database limit.

Since SQL Server Express 2005 was first released, people complained that it didn't provide full text search capabilities, among other things. With Service Pack 1, Microsoft has addressed this concern and others.

What many people don't know, however, is that part of the SP1 you can also download the Microsoft SQL Server 2005 Express Edition Toolkit SP1, which includes an Import/Export wizard, among other things. Just download it here and you will get the SQL Server Import and Export Wizard installed by default to "C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTSWizard.exe". You can even create a link to it straight from the Microsoft SQL Server Management Studio Express by going to Tools->External Tools and defining and Import/Export Wizard shortcut, by pointing the command parameter to "C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTSWizard.exe"

Download Link

SQL Server - "Arithmetic overflow error converting expression to data type int."

Today, when I tried to do a

view plain print about
1select count(*) from sometable cross join someothertable cross join athirdtable
I got the following error:

view plain print about
1Arithmetic overflow error converting expression to data type int.

Turns out you need to use the COUNT_BIG(*) function instead.

view plain print about
1select count_big(*) from sometable cross join someothertable cross join athirdtable

ProperCase Function for SQL Server

Have you ever wanted to convert some text that you have in a database to proper case? Maybe you have data that's all in uppercase or all in lowercase, and you want it displayed properly? Here is a handy function that will allow you to do this using just SQL queries, instead of resorting to pulling the data into another programming language like ColdFusion, as that would be a lot slower.

view plain print about
1set ANSI_NULLS ON
2set QUOTED_IDENTIFIER ON
3GO
4ALTER function [dbo].[ProperCase](@Text as varchar(8000))
5returns varchar(8000)
6as
7begin
8 declare @Reset bit;
9 declare @Ret varchar(8000);
10 declare @i int;
11 declare @c char(1);
12 declare @lookahead char(1);
13 declare @lookahead2 char(1);
14
15 select @Reset = 1, @i=1, @Ret = '';
16
17 while (@i <= len(@Text))
18    begin
19         select @c= substring(@Text,@i,1),@lookahead=substring(@Text,@i+1,1),@lookahead2=substring(@Text,@i+2,1),
20                 @Ret = @Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end,
21                 @Reset = case
22                            when @c like '[a-zA-Z]' then 0
23                            when @c like '''' and (@lookahead like '[sS]') and @lookahead2=' ' then 0
24                            else 1 end,
25                 @i = @i +1
26    
27    end
28 return @Ret
29end

So lets say you have data like this:

view plain print about
1select top 10 firstName from names
2
3firstname
4-----------
5AARON
6ABBEY
7ABBIE
8ABBY
9ABDUL
10ABE
11ABEL
12ABIGAIL
13ABRAHAM
14ABRAM
15
16(10 row(s) affected)

Lets see what it would look like proper cased:

view plain print about
1select top 10 dbo.properCase(firstName) as firstName from names
2
3firstName
4--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5Aaron
6Abbey
7Abbie
8Abby
9Abdul
10Abe
11Abel
12Abigail
13Abraham
14Abram
15
16(10 row(s) affected)

Now lets update the table and see the results:

view plain print about
1update names set firstName=dbo.properCase(firstname)
2select top 10 firstName from names
3firstName
4-----------
5Aaron
6Abbey
7Abbie
8Abby
9Abdul
10Abe
11Abel
12Abigail
13Abraham
14Abram
15
16(10 row(s) affected)

We've successfully updated all our names to propercase. Note that this function should work well with longer text and full sentences. Here is an example:

view plain print about
1select dbo.ProperCase('this,my friends, is a test.wHat DO you think?i like shaquile o''neal')
2
3--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4This,My Friends, Is A Test.What Do You Think?I Like Shaquile O'Neal
5
6(1 row(s) affected)

SQL Server Update with a join

Have you ever needed to update one table based on the contents of another table? The way to do it is with aliases.

view plain print about
1update t1 set t1.field=replace(t1.field, t2.field1, t2.field2) from table1 t1 inner join table2 t2 on t1.primaryKey=t2.foreignkey

SQL Server loops and prefilling table data

Let's say you need a table that has numbers from 1 to 10.

view plain print about
1declare @i integer
2set @i=0
3while (@i<10)
4 begin
5    insert into digits (digit) values (@i)
6    set @i=@i+1
7 end
8
9select * from digits

view plain print about
1digit
2------
30
41
52
63
74
85
96
107
118
129
13
14(10 row(s) affected)

Lets say you wanted all the letters in a table. Checking www.asciitable.com, we see that A has the ASCII value of 65, and Z has the ASCII value of 90.

view plain print about
1declare @i integer
2set @i=65
3while (@i<=90)
4 begin
5    insert into letters (letter) values (CHaR(@i))
6    set @i=@i+1
7 end
8
9select * from letters

view plain print about
1letter
2------
3A
4B
5C
6D
7E
8F
9G
10H
11I
12J
13K
14L
15M
16N
17O
18P
19Q
20R
21S
22T
23U
24V
25W
26X
27Y
28Z
29
30(26 row(s) affected)

Deleting duplicate rows from SQL Server

Lets say you have a table with duplicate data in it, and you'd like to get rid of it easily. For simplicity's sake, lets say you have a table named names and it contains two columns, nameid and firstname.

view plain print about
1select top 10 * from names order by firstName
view plain print about
1nameId firstName
2----------- -----------
377 AARON
43920 AARON
52802 ABBEY
62260 ABBIE
71913 ABBY
8831 ABDUL
9854 ABE
10485 ABEL
111739 ABIGAIL
12347 ABRAHAM

You can see right off the bat, that you have 2 Aaron's. Lets find out how many duplicate names you have total.

view plain print about
1select firstName from names group by firstName having count(firstName)>1 order by firstName
view plain print about
1firstName
2-----------
3AARON
4ADAM
5ADRIAN
6ALBERT
7ALEX
8ALEXANDER
9ALEXIS
10ALI
11ALLEN
12ALVA
13ANDRE
14ANDREA
15ANDREW
16ANGEL
17ANGELO
18ANTHONY
19ANTONIA
20ANTONIO
21ARIEL
22ARTHUR
23ASHLEY
24AUBREY
25AUGUSTINE
26AUSTIN
27AVERY
28BENNIE
29BERNIE
30BERRY
31BILLIE
32BILLY
33BLAIR
34BLAKE
35BOBBIE
36BOBBY
37BRANDON
38BRETT
39BRIAN
40BRITT
41CAMERON
42CAREY
43CARL
44CARLOS
45CARMEN
46CAROL
47CARROL
48CARROLL
49CARY
50CASEY
51CECIL
52CHANG
53CHARLES
54CHARLIE
55CHI
56CHONG
57CHRIS
58CHRISTIAN
59CHRISTOPHER
60CHUNG
61CLAIR
62CLARENCE
63CLAUDE
64CLEO
65CLYDE
66CODY
67COLBY
68CONNIE
69COREY
70CORY
71COURTNEY
72CRUZ
73CURTIS
74DALE
75DALLAS
76DAN
77DANA
78DANIEL
79DANNIE
80DARNELL
81DARYL
82DAVID
83DEAN
84DEE
85DEMETRIUS
86DENNIS
87DENNY
88DEON
89DEVIN
90DEVON
91DION
92DOMINIQUE
93DONALD
94DONG
95DONNIE
96DORIAN
97DREW
98DUSTY
99EDDIE
100EDWARD
101ELISHA
102ELLIS
103ELMER
104ERIC
105ERIN
106EUGENE
107EVAN
108FRANCES
109FRANCIS
110FRANCISCO
111FRANK
112FRANKIE
113FRED
114FREDDIE
115GABRIEL
116GAIL
117GALE
118GARY
119GAYLE
120GENE
121GEORGE
122GERALD
123GERRY
124GLENN
125GREGORY
126GUADALUPE
127HAROLD
128HENRY
129HOLLIS
130HONG
131IRA
132IVORY
133JACK
134JACKIE
135JAE
136JAIME
137JAME
138JAMES
139JAMEY
140JAMIE
141JAN
142JASON
143JAY
144JEAN
145JEFFREY
146JEREMY
147JERRY
148JESSE
149JESSIE
150JESUS
151JEWEL
152JEWELL
153JIMMIE
154JIMMY
155JOAN
156JODY
157JOE
158JOEL
159JOEY
160JOHN
161JOHNIE
162JOHNNIE
163JOHNNY
164JON
165JORDAN
166JOSE
167JOSEPH
168JOSHUA
169JUAN
170JUDE
171JULIAN
172JULIO
173JUSTIN
174KARL
175KASEY
176KEITH
177KELLEY
178KELLY
179KENDALL
180KENNETH
181KERRY
182KEVIN
183KIM
184KIRBY
185KRIS
186KYLE
187LACY
188LANE
189LARRY
190LAUREN
191LAURENCE
192LAVERN
193LAVERNE
194LAWRENCE
195LEE
196LEIGH
197LEO
198LEON
199LESLEY
200LESLIE
201LESTER
202LEWIS
203LINDSAY
204LINDSEY
205LOGAN
206LONNIE
207LOREN
208LOU
209LOUIE
210LOUIS
211LUIS
212LUPE
213LYNN
214MAN
215MARIA
216MARIO
217MARION
218MARK
219MARLIN
220MARSHALL
221MARTIN
222MARTY
223MARY
224MATTHEW
225MAURICE
226MELVIN
227MERLE
228MERRILL
229MICAH
230MICHAEL
231MICHAL
232MICHEAL
233MICHEL
234MICKEY
235MIKE
236MINH
237MITCHELL
238MORGAN
239NICKY
240NOEL
241NORMAN
242NUMBERS
243ODELL
244OLLIE
245OSCAR
246OTHA
247PARIS
248PAT
249PATRICIA
250PATRICK
251PAUL
252PERRY
253PETER
254QUINN
255RANDY
256RAY
257RAYMOND
258REFUGIO
259RENE
260RICHARD
261RICKIE
262ROBBIE
263ROBERT
264ROBERTO
265ROBIN
266RONALD
267RONNIE
268RORY
269ROSARIO
270ROY
271ROYCE
272RUDY
273RUSSELL
274RYAN
275SAM
276SAMMIE
277SAMMY
278SAMUEL
279SANDY
280SANG
281SANTOS
282SCOTT
283SCOTTIE
284SEAN
285SHANE
286SHANNON
287SHAUN
288SHAWN
289SHAYNE
290SHELBY
291SHIRLEY
292SIDNEY
293SOL
294SON
295STACEY
296STACY
297STEPHEN
298STEVEN
299STEVIE
300SUNG
301SYDNEY
302TAYLOR
303TERRELL
304TERRY
305THANH
306THEO
307THOMAS
308TIMOTHY
309TOBY
310TOMMIE
311TOMMY
312TONY
313TORY
314TRACEY
315TRACY
316TRAVIS
317TRINIDAD
318TRISTAN
319TROY
320TYLER
321VAL
322VALENTINE
323VAN
324VERNON
325VICTOR
326VIRGIL
327WALTER
328WESLEY
329WHITNEY
330WILLIAM
331WILLIE
332YONG
333YOUNG
334
335(331 row(s) affected)

Turns out we have 331 duplicate names. Now, how do we get the Id of only 1 of the names?

view plain print about
1select max(nameId) as nameId, firstName from names group by firstName having count(firstName)>1 order by firstName
view plain print about
1nameId firstName
2----------- -----------
33920 AARON
45053 ADAM
52178 ADRIAN
64673 ALBERT
73879 ALEX
83389 ALEXANDER
91676 ALEXIS
103653 ALI
114267 ALLEN
122391 ALVA
133744 ANDRE
141300 ANDREA
153422 ANDREW
161643 ANGEL
174265 ANGELO
183349 ANTHONY
191645 ANTONIA
203368 ANTONIO
212332 ARIEL
223916 ARTHUR
231282 ASHLEY
242284 AUBREY
253165 AUGUSTINE
265400 AUSTIN
274446 AVERY
282282 BENNIE
294107 BERNIE
304557 BERRY
311497 BILLIE
322700 BILLY
332575 BLAIR
345397 BLAKE
351507 BOBBIE
362238 BOBBY
373983 BRANDON
384361 BRETT
394801 BRIAN
403328 BRITT
413081 CAMERON
422134 CAREY
433366 CARL
444614 CARLOS
451330 CARMEN
461237 CAROL
472652 CARROL
482491 CARROLL
492713 CARY
501680 CASEY
512557 CECIL
524555 CHANG
532473 CHARLES
542412 CHARLIE
553387 CHI
562291 CHONG
571747 CHRIS
582122 CHRISTIAN
593187 CHRISTOPHER
603417 CHUNG
613161 CLAIR
625120 CLARENCE
634953 CLAUDE
641815 CLEO
653279 CLYDE
663592 CODY
675300 COLBY
681325 CONNIE
692598 COREY
702748 CORY
711464 COURTNEY
722405 CRUZ
735297 CURTIS
741915 DALE
753386 DALLAS
765036 DAN
771398 DANA
782540 DANIEL
794551 DANNIE
803562 DARNELL
813589 DARYL
822488 DAVID
832920 DEAN
841917 DEE
854354 DEMETRIUS
863620 DENNIS
875386 DENNY
884548 DEON
892825 DEVIN
902373 DEVON
915290 DION
921891 DOMINIQUE
933873 DONALD
945112 DONG
952614 DONNIE
963384 DORIAN
974492 DREW
983301 DUSTY
992076 EDDIE
1004053 EDWARD
1012242 ELISHA
1025379 ELLIS
1035032 ELMER
1043644 ERIC
1051379 ERIN
1064212 EUGENE
1074211 EVAN
1081266 FRANCES
1091612 FRANCIS
1103943 FRANCISCO
1113910 FRANK
1121789 FRANKIE
1135031 FRED
1142323 FREDDIE
1153254 GABRIEL
1161374 GAIL
1171909 GALE
1183760 GARY
1191594 GAYLE
1202518 GENE
1212535 GEORGE
1224784 GERALD
1232562 GERRY
1244942 GLENN
1254489 GREGORY
1261523 GUADALUPE
1274727 HAROLD
1283558 HENRY
1293537 HOLLIS
1302846 HONG
1312754 IRA
1322604 IVORY
1334436 JACK
1341454 JACKIE
1354168 JAE
1361717 JAIME
1375185 JAME
1382094 JAMES
1394126 JAMEY
1401365 JAMIE
1411559 JAN
1423731 JASON
1433345 JAY
1441277 JEAN
1454862 JEFFREY
1465276 JEREMY
1472057 JERRY
1482263 JESSE
1491434 JESSIE
1503500 JESUS
1511741 JEWEL
1521803 JEWELL
1531886 JIMMIE
1544012 JIMMY
1551281 JOAN
1561621 JODY
1572517 JOE
1583867 JOEL
1593114 JOEY
1602038 JOHN
1613158 JOHNIE
1621610 JOHNNIE
1633344 JOHNNY
1644480 JON
1652011 JORDAN
1662927 JOSE
1672581 JOSEPH
1684860 JOSHUA
1693077 JUAN
1704541 JUDE
1714011 JULIAN
1725367 JULIO
1734010 JUSTIN
1744089 KARL
1752066 KASEY
1765018 KEITH
1771669 KELLEY
1781286 KELLY
1792733 KENDALL
1803803 KENNETH
1811671 KERRY
1823381 KEVIN
1831337 KIM
1843938 KIRBY
1852052 KRIS
1862807 KYLE
1872151 LACY
1883864 LANE
1894381 LARRY
1901381 LAUREN
1914848 LAURENCE
1922529 LAVERN
1931674 LAVERNE
1944711 LAWRENCE
1951560 LEE
1961658 LEIGH
1974845 LEO
1984589 LEON
1991831 LESLEY
2001362 LESLIE
2015447 LESTER
2025355 LEWIS
2031521 LINDSAY
2041520 LINDSEY
2054772 LOGAN
2062555 LONNIE
2072504 LOREN
2081823 LOU
2094041 LOUIE
2102550 LOUIS
2114000 LUIS
2121821 LUPE
2131385 LYNN
2144526 MAN
2151226 MARIA
2163376 MARIO
2171397 MARION
2182767 MARK
2195007 MARLIN
2205438 MARSHALL
2214240 MARTIN
2222716 MARTY
2231220 MARY
2243935 MATTHEW
2253965 MAURICE
2264287 MELVIN
2272058 MERLE
2284523 MERRILL
2293632 MICAH
2302018 MICHAEL
2313964 MICHAL
2323994 MICHEAL
2333441 MICHEL
2342689 MICKEY
2355160 MIKE
2363932 MINH
2374329 MITCHELL
2381795 MORGAN
2393664 NICKY
2402452 NOEL
2413601 NORMAN
2423335 NUMBERS
2433129 ODELL
2441716 OLLIE
2455339 OSCAR
2464283 OTHA
2473225 PARIS
2481606 PAT
2491221 PATRICIA
2503266 PATRICK
2513013 PAUL
2523928 PERRY
2535250 PETER
2544910 QUINN
2552914 RANDY
2562567 RAY
2574282 RAYMOND
2583750 REFUGIO
2591893 RENE
2602792 RICHARD
2614906 RICKIE
2621872 ROBBIE
2632215 ROBERT
2644687 ROBERTO
2651319 ROBIN
2663961 RONALD
2672730 RONNIE
2685245 RORY
2691817 ROSARIO
2704989 ROY
2714419 ROYCE
2724231 RUDY
2735423 RUSSELL
2742448 RYAN
2753600 SAM
2762502 SAMMIE
2774571 SAMMY
2785333 SAMUEL
2791541 SANDY
2803370 SANG
2812831 SANTOS
2823960 SCOTT
2834683 SCOTTIE
2843775 SEAN
2853491 SHANE
2861342 SHANNON
2873889 SHAUN
2881751 SHAWN
2894984 SHAYNE
2901738 SHELBY
2911246 SHIRLEY
2922702 SIDNEY
2935236 SOL
2943851 SON
2951430 STACEY
2961399 STACY
2973819 STEPHEN
2983886 STEVEN
2993627 STEVIE
3003488 SUNG
3012230 SYDNEY
3022024 TAYLOR
3034818 TERRELL
3041472 TERRY
3053423 THANH
3063816 THEO
3073015 THOMAS
3084561 TIMOTHY
3092764 TOBY
3101997 TOMMIE
3112923 TOMMY
3122763 TONY
3134456 TORY
3141499 TRACEY
3151327 TRACY
3165226 TRAVIS
3172487 TRINIDAD
3184031 TRISTAN
3194367 TROY
3203882 TYLER
3213881 VAL
3224454 VALENTINE
3232935 VAN
3245408 VERNON
3254816 VICTOR
3265405 VIRGIL
3274143 WALTER
3284674 WESLEY
3291587 WHITNEY
3302337 WILLIAM
3311438 WILLIE
3322307 YONG
3332121 YOUNG
334
335(331 row(s) affected)
Now we can delete the record with the highest id.
view plain print about
1delete from names where nameID IN (select max(nameId) as nameId from names group by firstName having count(firstName)>1)
2(331 row(s) affected)

If you wanted to delete the record with the lowest Id, you would run this code:

view plain print about
1delete from names where nameID IN (select min(nameId) as nameId from names group by firstName having count(firstName)>1)
2(331 row(s) affected)

If you have more then 1 set of duplicates, you can just run the last piece of code a bunch of times until you have no more rows affected, or you can put it in a loop.