dbTalk Databases Forums  

Update Query

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Update Query in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
anonymous
 
Posts: n/a

Default Update Query - 02-09-2005 , 09:06 AM






Maybe some one can help me...
I have 2 tables with the following structure:
CREATE TABLE [table1](
[GRID] [int] IDENTITY (1, 1) NOT NULL ,
[GID] [varchar] (10) NOT NULL ,
[RID] [int] NOT NULL ) On primary


CREATE TABLE [table2] (
[RID] [int] IDENTITY (1, 1) NOT NULL ,
[RText] [varchar] (400) NULL
) ON [PRIMARY]

If [RID] in table 1 exists more then one time (the first
occurence leave as is)
and then create a new [RID] every time it is found in
table2 with the RText from [RID] and update table1 with
applicable [RID] .



Reply With Quote
  #2  
Old   
Adam Machanic
 
Posts: n/a

Default Re: Update Query - 02-09-2005 , 10:04 AM






Can you post some sample data and sample output? I'm having trouble
following your logic...

--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


"anonymous" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Maybe some one can help me...
I have 2 tables with the following structure:
CREATE TABLE [table1](
[GRID] [int] IDENTITY (1, 1) NOT NULL ,
[GID] [varchar] (10) NOT NULL ,
[RID] [int] NOT NULL ) On primary


CREATE TABLE [table2] (
[RID] [int] IDENTITY (1, 1) NOT NULL ,
[RText] [varchar] (400) NULL
) ON [PRIMARY]

If [RID] in table 1 exists more then one time (the first
occurence leave as is)
and then create a new [RID] every time it is found in
table2 with the RText from [RID] and update table1 with
applicable [RID] .





Reply With Quote
  #3  
Old   
anonymous
 
Posts: n/a

Default Re: Update Query - 02-09-2005 , 02:31 PM



I hope this helps:
Before Update:
table1:
[GRID] [GID] [RID]
102 2 1
103 3 1

table2:
[RID] [RText]
1 Rtext

After Update:
table1:
[GRID] [GID] [RID]
102 2 1
103 3 2

table2:
[RID] [RText]
1 Rtext
2 Rtext

Reply With Quote
  #4  
Old   
Adam Machanic
 
Posts: n/a

Default Re: Update Query - 02-09-2005 , 09:38 PM



What is the logic you're using here? And what are your keys? Table2
appears to not have a primary key at all..?

--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


"anonymous" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
I hope this helps:
Before Update:
table1:
[GRID] [GID] [RID]
102 2 1
103 3 1

table2:
[RID] [RText]
1 Rtext

After Update:
table1:
[GRID] [GID] [RID]
102 2 1
103 3 2

table2:
[RID] [RText]
1 Rtext
2 Rtext



Reply With Quote
  #5  
Old   
anonymous
 
Posts: n/a

Default Re: Update Query - 02-10-2005 , 10:24 AM



Table1 has a PK:[GRID] [GID]
we are changing 1 to many relationship.
Quote:
-----Original Message-----
What is the logic you're using here? And what are your
keys? Table2
appears to not have a primary key at all..?

--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


"anonymous" <anonymous (AT) discussions (DOT) microsoft.com> wrote
in message
news:137001c50ee6$4786ca10$a601280a (AT) phx (DOT) gbl...
I hope this helps:
Before Update:
table1:
[GRID] [GID] [RID]
102 2 1
103 3 1

table2:
[RID] [RText]
1 Rtext

After Update:
table1:
[GRID] [GID] [RID]
102 2 1
103 3 2

table2:
[RID] [RText]
1 Rtext
2 Rtext


.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.