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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Simple Sp - I thought

Author  Topic 

timsweet
Starting Member

31 Posts

Posted - 2005-08-29 : 11:11:57
Quick questions.

I have a table that has a customer Id with multiple enteries.

(Source table)
fldCustomerId fldType flddetails
1 CEll 555-555-55555
1 Email 666-666-6666
1 Home 777-777-7777

I need to update a table thats has each of the fldType fields' data as a separate field

(table to update)
fldCustomerId fldCell fldEMail fldHome
1 XX XX XX
Then all of the data from flddetails (above) populates here (XX)

Any suggestion?

Thanks in advance

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-08-29 : 11:26:45
insert into tablea (cola1, cola2, cola3, cola4)
select b.id, b.cell, c.email, d.home from tableb
innerjoin tablec on b.id = c.id and c.type='email'
innerjoin tabled on b.id = d.id and d.type='home'
where b.type='cell'


substitute tablea,b,c,d with the real table names....a small of exercise for you!!
Go to Top of Page

timsweet
Starting Member

31 Posts

Posted - 2005-08-29 : 12:47:43
Thank you for the response. I don't see that working for me. I only have two tables one source and the other - I'm updating exising data. The customer Id already exist.

My select statement returns
Cust# Type Details
1234 Email here@there.com
1234 Cell 555-555-5555

the table I need to update has
Cust# Email Cell Home
1234 here@there.com Null NUll

Insert of course isn't what I'm looking. I need to update EMail filed with the data for the Details Field.


Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-08-30 : 05:43:14
tableb, tablec and tabled are all the same table 'aliased' with different letters....
it's called SELF-JOINs...read/search here (and BOL) for examples.
Go to Top of Page
   

- Advertisement -