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 2008 Forums
 Transact-SQL (2008)
 Updating Varchar Variable in 1 table frm 2 tables

Author  Topic 

jayram11
Yak Posting Veteran

97 Posts

Posted - 2010-09-22 : 16:08:15
Hi
I have table A with code and description variable
Table B with ID and Descriptions variable
table C with Type and Definition variable

table A
CODE Description
BA141 Null

table B
ID Descriptions
BA1 long march

table C
Type Definitions
41 to heaven


i need to populate table A with Long March to heaven from table B and C

table A
CODE Description
BA141 long march to heaven

basically the first three left characters comes from table B and last 2 from table C. My table A has a 1000 record with combination of ID and type as code from Table B and C. i have some 30+ ID in B and 30+ in C

Canyou haelp?

Jkr


jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-09-22 : 17:46:13
UPDATE A
SET DESCRIPTION = b.Descriptions + c.Defintions
FROM tableA A
INNER JOIN tableB B
ON
LEFT(a.CODE,3) = b.ID
INNER JOIN tableC C ON
RIGHT(a.code,2) = c.[type]

This will get a lot harder when you want to account for Codes that aren't 5 characters long, or link on somthing other than lefft 3 and right 2

Jim

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

- Advertisement -