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)
 help with writing query

Author  Topic 

sardinka
Posting Yak Master

142 Posts

Posted - 2006-04-14 : 08:34:48
Please help with writing query
I have 2 tables:
Table1:
ID Description
1 name1
2 name2
3 name3...

Table2:
SiD ID
123 1
456 2
789 myname
852 yourname

if description exisits in table1 get description from table1 in
all other cases get ID from table2

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-14 : 08:37:18
Post your expected data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sardinka
Posting Yak Master

142 Posts

Posted - 2006-04-14 : 08:53:16
Name1
name2
myname
yourname
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-14 : 09:19:45
Why did you store id and description in the same column in table2?

You can try something like this

select Description from table1 t1 left join table2 t2
on t1.id=T2.id
where t2.sid is not null
union all
select t2.id from table1 t1 right join table2 t2
on t1.id=T2.id where t1.id is null


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -