Author |
Topic |
Pankaj Kumar
Starting Member
6 Posts |
Posted - 2012-12-04 : 08:52:06
|
Suppose I have Table 1 in which a family having members Table 1Membername -- Relation -- FamilyID ABC -- 1 ---- 54321234 -- 2 ---- 5432XYZ -- 3 ---- 5432UYX -- 4 ---- 5432AZS -- 5 ---- 5432RAM -- 1 ---- 76541234 -- 2 ---- 7654RBS -- 3 ---- 7654 Table 2EName -- URN-------------FamilyIDABC -- 0912341325132----5432RAM -- 0912563574848----7654I want to replace 1234 in membername in table1 with "family of table2.EName"(Membername) in Relation 2 with match query table2.familyid = table1.familyidIs there any Query to Replace 1234 with"Family of ABC or RAM"Please help me |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-04 : 09:02:16
|
EDIT: Ignore this post. My answer is irrelevant to your modified postdeclare @tab TABLE(Membername varchar(20),Relation int)insert into @tab SELECT 'ABC', 1 union allSELECT '1234', 2 union allSELECT 'XYZ', 3 union allSELECT 'UYX', 4 union allSELECT 'AZS', 5update @tab set Membername = 'Family of ABC'WHERE ISNUMERIC(Membername) =1SELECT * FROM @tab--Chandu |
|
|
Pankaj Kumar
Starting Member
6 Posts |
Posted - 2012-12-04 : 09:16:06
|
I want an SQL Query to replace the relation-2 name in different multiple families. |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-12-04 : 09:29:08
|
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? |
|
|
Pankaj Kumar
Starting Member
6 Posts |
Posted - 2012-12-04 : 09:34:27
|
You please read the post again.I Updated the post |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-12-04 : 09:51:44
|
UPDATE t1SET MemberName = t2.EnameFROM Table1 t1 INNER JOIN Table2 t2 on t1.FamilyID = t2.FamilyIDWHERE t1.memberName = '1234'JimEveryday I learn something that somebody else already knew |
|
|
Pankaj Kumar
Starting Member
6 Posts |
Posted - 2012-12-04 : 11:46:24
|
@JimfI know this query but I want to update 1234 as "Family of t2.Ename"So please help me. |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-12-04 : 11:51:23
|
quote: Originally posted by jimf UPDATE t1SET MemberName = 'Family of ' + t2.EnameFROM Table1 t1 INNER JOIN Table2 t2 on t1.FamilyID = t2.FamilyIDWHERE t1.memberName = '1234'JimEveryday I learn something that somebody else already knew
|
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-12-04 : 11:52:52
|
You can perhaps add that specific string to Jim's query? What I mean isUPDATE t1SET MemberName = 'Family of ' + t2.EnameFROM Table1 t1 INNER JOIN Table2 t2 on t1.FamilyID = t2.FamilyIDWHERE t1.memberName = '1234' |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-12-04 : 11:53:47
|
Maybe you could post what you expect the new table to look like, I'm having trouble following what you wantJimEveryday I learn something that somebody else already knew |
|
|
Pankaj Kumar
Starting Member
6 Posts |
Posted - 2012-12-04 : 12:05:24
|
Great .......Thanks So Much for helping me.... |
|
|
|