SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help me to enter the name as suffix in the table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Pankaj Kumar
Starting Member

India
6 Posts

Posted - 12/04/2012 :  08:52:06  Show Profile  Reply with Quote
Suppose I have Table 1 in which a family having members

Table 1
Membername -- Relation -- FamilyID
ABC -- 1 ---- 5432
1234 -- 2 ---- 5432
XYZ -- 3 ---- 5432
UYX -- 4 ---- 5432
AZS -- 5 ---- 5432
RAM -- 1 ---- 7654
1234 -- 2 ---- 7654
RBS -- 3 ---- 7654


Table 2

EName -- URN-------------FamilyID
ABC -- 0912341325132----5432
RAM -- 0912563574848----7654

I want to replace 1234 in membername in table1 with "family of table2.EName"(Membername) in Relation 2 with match query table2.familyid = table1.familyid

Is there any Query to Replace 1234 with"Family of ABC or RAM"

Please help me

Edited by - Pankaj Kumar on 12/04/2012 09:32:23

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 12/04/2012 :  09:02:16  Show Profile  Reply with Quote
EDIT: Ignore this post. My answer is irrelevant to your modified post
declare @tab TABLE(Membername varchar(20),Relation int)
insert into @tab
SELECT 'ABC', 1 union all
SELECT '1234', 2 union all
SELECT 'XYZ', 3 union all
SELECT 'UYX', 4 union all
SELECT 'AZS', 5

update @tab
set Membername = 'Family of ABC'
WHERE ISNUMERIC(Membername) =1
SELECT * FROM @tab

--
Chandu

Edited by - bandi on 12/05/2012 00:20:32
Go to Top of Page

Pankaj Kumar
Starting Member

India
6 Posts

Posted - 12/04/2012 :  09:16:06  Show Profile  Reply with Quote
I want an SQL Query to replace the relation-2 name in different multiple families.
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/04/2012 :  09:29:08  Show Profile  Reply with Quote
If you have several families in one table:

-- How is a row identified as being a family vs a member of a family?

-- How are individual families identified? In other words, what piece of information should be used to designate 1234 as being "Family of ABC" (and not "Family of XYZ"), if indeed there was another family named XYZ?
Go to Top of Page

Pankaj Kumar
Starting Member

India
6 Posts

Posted - 12/04/2012 :  09:34:27  Show Profile  Reply with Quote
You please read the post again.

I Updated the post
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 12/04/2012 :  09:51:44  Show Profile  Reply with Quote
UPDATE t1
SET MemberName = t2.Ename
FROM Table1 t1
INNER JOIN Table2 t2 on t1.FamilyID = t2.FamilyID
WHERE t1.memberName = '1234'

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Pankaj Kumar
Starting Member

India
6 Posts

Posted - 12/04/2012 :  11:46:24  Show Profile  Reply with Quote
@Jimf

I know this query but I want to update 1234 as "Family of t2.Ename"

So please help me.
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4354 Posts

Posted - 12/04/2012 :  11:51:23  Show Profile  Reply with Quote
quote:
Originally posted by jimf

UPDATE t1
SET MemberName = 'Family of ' + t2.Ename
FROM Table1 t1
INNER JOIN Table2 t2 on t1.FamilyID = t2.FamilyID
WHERE t1.memberName = '1234'

Jim

Everyday I learn something that somebody else already knew

Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/04/2012 :  11:52:52  Show Profile  Reply with Quote
You can perhaps add that specific string to Jim's query? What I mean is

UPDATE t1
SET MemberName = 'Family of ' + t2.Ename
FROM Table1 t1 
INNER JOIN Table2 t2 on t1.FamilyID = t2.FamilyID
WHERE t1.memberName = '1234'
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 12/04/2012 :  11:53:47  Show Profile  Reply with Quote
Maybe you could post what you expect the new table to look like, I'm having trouble following what you want


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Pankaj Kumar
Starting Member

India
6 Posts

Posted - 12/04/2012 :  12:05:24  Show Profile  Reply with Quote
Great .......

Thanks So Much for helping me....
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000