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 2000 Forums
 SQL Server Development (2000)
 Query help needed

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) 100
Table2 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 table2
I 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 Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

sardinka
Posting Yak Master

142 Posts

Posted - 2006-05-31 : 08:28:32
Table1:
1
2
10
Description1
12
Description2
Table2:
1 MyDescription1
2 MyDescription2
3 MyDescription3...





Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-05-31 : 08:55:51
I hope you're doing this for normalisation purposes...

--data
declare @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'

--calculation
select isnull(b.Description, a.Description) as Description
from @Table1 a
left outer join @Table2 b on a.Description = cast(IDDescription as varchar(10))

/*results
Description
-------------------
MyDescription1
MyDescription2
abc
Description1
xyz
Description2
*/


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -