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 |
zajacv
Starting Member
2 Posts |
Posted - 2008-04-28 : 09:45:51
|
Hello,Is it possible based on values within certain columns, to either do a join or just pass a value? For example, If colA=1 and colB=2 and colC=3 then 1 as ColA else inner join on tableA.colA = tableb.ColAThanks |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-28 : 09:52:50
|
You have to elaborate more. Please post some sample data and expected output.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-28 : 10:34:37
|
You cant have condition based joins unless you use dynamic sql. But the same effect can be achieved by taking the join and using case in select list to selectively take the value. You need toprovide more information on what you are trying to achieve with some sample data from table and o/p you desire to get more help. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-28 : 10:40:29
|
You can, as a correlated subquery.But remember that the correlated subquery only can return 1 column and 1 record. E 12°55'05.25"N 56°04'39.16" |
 |
|
zajacv
Starting Member
2 Posts |
Posted - 2008-04-28 : 11:27:09
|
Ok I have lookup table basically, lets call it tableA with colA and colB with the following data:tableAcolA colB123 1321 2544 3then I have tableB with the following:tableBcolA colB colC 123 1 c 321 2 b555 3 c421 4 cIf tableB colA = 555 and tableB colc = c then I want to pass 555 in colA however if these conditions are not met then I want to join to tableA on colA and return colB I know I can do this doing a simple union all but its a fairly large table and I don't want to have to scan it twice by doing 2 separate selectsThanks |
 |
|
|
|
|