Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2005, 01:20 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Flag Unique RowID in Sql Server 2000

Hi,

I am trying to flag the Unique RowID in SQL Server 2000. Something like this :

OptyID ManagedBy UniqueIdentifier
2-A23RT A Flag
2-A23RT B NULL
2-A23RT C NULL
1-QRT87 D Flag
A-89712 E Flag
A-89712 F NULL

So, it will go through with every single row and flag only the first unique OptyID (say "Flag"). If the ID repeats then it will set a NULL value.

Can someone please advice, how can i do that.

Your help would be greatly appreciated.

Thanks in advance
R
 
Old November 4th, 2005, 09:47 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here you go

create table BlahTable (OptyID varchar(10), ManagedBy char(1), [UniqueIdentifier] varchar(4))
insert into BlahTable
select '2-A23RT','A',NULL union all
select '2-A23RT','B',NULL union all
select '2-A23RT','C',NULL union all
select '1-QRT87','D',NULL union all
select 'A-89712','E', NULL union all
select 'A-89712','F',NULL

update b
set [UniqueIdentifier] = 'FLAG'
From BlahTable b join(
select OptyID,Min(ManagedBy) ManagedBy from BlahTable
group by OptyID) z on b.OptyID = z.OptyID and z.ManagedBy =b.ManagedBy

select * from BlahTable


“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old November 4th, 2005, 10:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

I feel obligated to point out that SqlMenace's response "flag"s the row with the lowest (i.e. MIN) ManagedBy value for each OptyID.

The OP asked for the "first"; not necessarily the same thing.

On the other hand, the concept of "first" has no meaning in SQL. Since rows in a table are unordered, there can be no meaning to the concept of a "first" row, which implies an ordering of some sort.

Thus, SqlMenace's solution is as correct as it could be, given the flawed premise.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old November 6th, 2005, 06:20 PM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a million. I very much appreciate it.

R

 
Old November 6th, 2005, 11:41 PM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Firstly Thank heaps. this is my exact situation. Sometimes opty are managed by same person but different product attached to the opty and sometimes opty is managed by different people but it has got same product attached. Like the example below :

OptyID ManagedBy Product UniqueIdentifier
2-A23RT A AA Flag
2-A23RT B AA
2-A23RT C AA
1-QRT87 D WQ Flag
1-A89712 E TR Flag
1-A89713 E RV
1-A89714 E ZZ
8-A89714 A AA Flag

Your query works fine if i take product off the table. Any ideas how to fix it?

thanks for your help
R






Similar Threads
Thread Thread Starter Forum Replies Last Post
Conflict in SQL Server 2000 and SQL Server 2005 ayan.mukherjee SQL Language 0 June 30th, 2008 03:34 AM
Difference between rowid and rownum in sql query?? bikash SQL Language 2 November 9th, 2006 03:58 PM
SQL Server 2000 and SQL Server 2000 CE dparsons SQL Server 2000 1 July 31st, 2006 12:59 PM
looking for access 2000 to sql server 2000 sql/que method SQL Server 2000 0 July 7th, 2005 12:46 PM
SQL SERVER 2000 AND ACCESS 2000 ckentebe SQL Server 2000 3 June 17th, 2004 08:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.