Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 what to update the duplicate records

Author  Topic 

shaggy
Posting Yak Master

248 Posts

Posted - 2007-07-11 : 01:31:22
hi,

i want to update the second row of the c column.can any one help me in this . this is the sample records.
a b c
001 test NULL
001 test NULL
005 test NULL

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-11 : 01:33:31
Why second row ? Why not 1st row ? Isn't it both are the same ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

shaggy
Posting Yak Master

248 Posts

Posted - 2007-07-11 : 01:37:41
1st r 2nd row
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-11 : 02:22:15
You need unique key to identify the row

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

noorahmed.shaik
Starting Member

11 Posts

Posted - 2007-07-11 : 04:54:01
u can use cursors to update the record which ever u need...

one simple example i am showing here

declare cur_name cursor scroll dynamic 
for select * from table_name


open cur_name


fetch absolute 2 from cur_name

udate table_name
set c=something
where current of cur_name




Noor Ahmed
Keysoft solution
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-07-11 : 06:57:53
You CAN use a cursor, but dont. Do a forum search and read the 4326546568 hits on why you should not, and on what alternatives you have (A set based solution).

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-11 : 10:20:45
update t
set t.c = t.recid
from (select c, row_number() over (partition by a) as recid) as t
where t.recid > 1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-12 : 00:41:12
quote:
Originally posted by Peso

update t
set t.c = t.recid
from (select c, row_number() over (partition by a) as recid) as t
where t.recid > 1


Peter Larsson
Helsingborg, Sweden


Provided the user is using SQL Server 2005

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-12 : 02:04:03
I assume "New to SQL Server" in the year of 2007 (soon 2008), are using SQL Server 2005 in favor of SQL Server 2000.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-12 : 05:32:46
quote:
Originally posted by Peso

I assume "New to SQL Server" in the year of 2007 (soon 2008), are using SQL Server 2005 in favor of SQL Server 2000.


Peter Larsson
Helsingborg, Sweden

Well. Not every company has moved to 2005

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-12 : 05:35:26
Well, Not all my customer is willing to move to 2005 yet


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-12 : 05:43:08
quote:
Originally posted by khtan

Well, Not all my customer is willing to move to 2005 yet


KH
[spoiler]Time is always against us[/spoiler]




Well.That makes more sense

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-12 : 15:06:32
"Not willing to move to SQL Server 2005" implies they are using SQL Server 2000 already, and as such they can't be treated as "new" to SQL Server, right?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-12 : 23:25:26
quote:
Originally posted by Peso

"Not willing to move to SQL Server 2005" implies they are using SQL Server 2000 already, and as such they can't be treated as "new" to SQL Server, right?


Peter Larsson
Helsingborg, Sweden

What if new employee who is also new to SQL Server joined in that company?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-12 : 23:44:11
Maybe we should have a separate forum for each version
- New to SQL Server 2000
- New to SQL Server 2005
- New to SQL Server 2008

And to make it better. Have one for each of the edition .
- New to SQL Server 2005 (Standard & Enterprise & Developer Edition)
- New to SQL Server 2005 (Express Edition)
- New to SQL Server 2005 (Compact Edition)

Maybe at the end newbie will still post to a general "New to SQL Server" forum. "I don't know which version i am using"
That will be really messy


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-13 : 03:32:56
Don't forget 32-bit and 64-bit

I see your points.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-07-13 : 08:50:34
here's the stock answer to "New to SQL Server 2005 Enterprise":

stop now before you hurt someone!


elsasoft.org
Go to Top of Page
   

- Advertisement -