April 11, 2005 at 8:57 pm
I have 2 tables with data as.
Table A
FName LName Value
John Brown
Chris Smith
P DeSouza
P DeSilva
Table B
FullName
John Brown
Chris Smith
P De Souza
P De Silva
I am trying to write a query which will update Value column in Table A to 1 if FName and Last Name of a person exists as full Name in Table B. Also something which takes care of the spaces as shown in last 2 rows. Any help will be greatly appreciated.
TIA
April 11, 2005 at 11:20 pm
Select * from Tablea,Tableb Where TableA.Fname + ' ' + TableA.Lname = Tableb.Fullname
My Blog:
April 12, 2005 at 2:03 am
What is the reason why you want to keep permanently this redundant information?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
April 12, 2005 at 7:05 am
Thats how the database is designed initially. query works fine but not for last 2 rows how can those be updated if data matches in both tables.
April 12, 2005 at 7:50 am
Try using this:
Select * from Tablea,Tableb Where TableA.Fname + TableA.Lname = select replace(Tableb.Fullname, ' ', '')
**ASCII stupid question, get a stupid ANSI !!!**
April 12, 2005 at 1:34 pm
Hello, ISHANN99:
With update portion included:
create table tableB (Fullname varchar (50))
insert tableB values ('John Brown')
insert tableB values ('Chris Smith')
insert tableB values ('P De Souza')
insert tableB values ('P De Silva')
create table tableA (fname varchar(25), lname varchar(25), value int)
insert tableA values ('John', 'Brown',0)
insert tableA values ('Chris', 'Smith',0)
insert tableA values ('P', 'DeSouza',0)
insert tableA values ('P', 'DeSilva',0)
insert tableA values ('Linda', 'Carpenter',0)
insert tableA values ('John', 'Doe',0)
insert tableA values ('Mary', 'LittleLamb',0)
select * from tableA
select * from tableB
update tableA
set value = 1 where
REPLACE(fname+lname,' ','')
in(SELECT REPLACE(fullname,' ','') from tableB)
select * from tableA
HTH - Linda
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply