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 2005 Forums
 .NET Inside SQL Server (2005)
 case? decode?

Author  Topic 

asksql
Starting Member

11 Posts

Posted - 2008-06-08 : 20:10:34
Hello,

I need to do the following:

Lets say we have the following table.

A B C
1 XYZ XYZ
100

Now if the value of a is "100" then i need to do a join and get a value from another table, else I put the value of b a "test"

I am trying to do this using case

like this

select case
(when a = 100 then (select col from ....where newtable.id = a.id
else "test"
end) as xyz
from a,b,other tables.

But the problem is that the subquery returns more than one row..(it should return one row)

How do I do this?


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-09 : 00:21:59
Include a TOP 1 in the subquery.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -