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
 General SQL Server Forums
 New to SQL Server Programming
 Help me to enter the name as suffix in the table

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 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

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 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
Go to Top of Page

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.
Go to Top of Page

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?
Go to Top of Page

Pankaj Kumar
Starting Member

6 Posts

Posted - 2012-12-04 : 09:34:27
You please read the post again.

I Updated the post
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-12-04 : 09:51:44
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

6 Posts

Posted - 2012-12-04 : 11:46:24
@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
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-12-04 : 11:51:23
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
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 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
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 want


Jim

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

Pankaj Kumar
Starting Member

6 Posts

Posted - 2012-12-04 : 12:05:24
Great .......

Thanks So Much for helping me....
Go to Top of Page
   

- Advertisement -