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.
| Author |
Topic |
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2006-05-31 : 08:09:41
|
| I have 2 tables:Table1 has a field [Description](varchar) 100Table2 has a field [IDDescription] int and field [Description] varchar(100)In table 2 I have IDDescription store but some time also description wich is not store in table2I need to pull all description (if it is from table2 or table1). How do I do this? |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-05-31 : 08:12:32
|
| Could you give an example (of the data in each table and the result you would want for that data)?Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2006-05-31 : 08:28:32
|
| Table1:1210Description112Description2Table2:1 MyDescription12 MyDescription23 MyDescription3... |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-05-31 : 08:55:51
|
I hope you're doing this for normalisation purposes...--datadeclare @Table1 table (Description varchar(100))insert @Table1 select '1'union all select '2'union all select '10'union all select 'Description1'union all select '12'union all select 'Description2'declare @Table2 table (IDDescription int, Description varchar(100))insert @Table2 select 1, 'MyDescription1'union all select 2, 'MyDescription2'union all select 3, 'MyDescription3'union all select 10, 'abc'union all select 12, 'xyz'--calculationselect isnull(b.Description, a.Description) as Descriptionfrom @Table1 a left outer join @Table2 b on a.Description = cast(IDDescription as varchar(10))/*resultsDescription -------------------MyDescription1MyDescription2abcDescription1xyzDescription2*/ Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|