Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case inside a Join?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

DaveBF
Yak Posting Veteran

89 Posts

Posted - 03/04/2014 :  11:56:53  Show Profile  Reply with Quote
Is it possible to do something like this:

Select a.address from person p 
join Addresses a on p.AddressPointer =  
   Case when @UseNewAddress=1 then a.NewAddress else a.OldAddress end


It gives a syntax error but I'm wondering if there's another way to do it.

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 03/04/2014 :  12:25:05  Show Profile  Reply with Quote
quote:
Originally posted by DaveBF

Is it possible to do something like this:

Select a.address from person p 
join Addresses a on p.AddressPointer =  
   Case when @UseNewAddress=1 then a.NewAddress else a.OldAddress end


It gives a syntax error but I'm wondering if there's another way to do it.

What kind of syntax error are you getting? I don't see anything wrong with the syntax as long as you have defined the @UseNewAddress variable and p.AddressPointer, a.NewAddress and a.OldAddress are compatible types.
Go to Top of Page

DaveBF
Yak Posting Veteran

89 Posts

Posted - 03/04/2014 :  12:30:38  Show Profile  Reply with Quote
quote:
Originally posted by James K

quote:
Originally posted by DaveBF

Is it possible to do something like this:

Select a.address from person p 
join Addresses a on p.AddressPointer =  
   Case when @UseNewAddress=1 then a.NewAddress else a.OldAddress end


It gives a syntax error but I'm wondering if there's another way to do it.

What kind of syntax error are you getting? I don't see anything wrong with the syntax as long as you have defined the @UseNewAddress variable and p.AddressPointer, a.NewAddress and a.OldAddress are compatible types.




Ooops! Sorry about this. You're right. I had something else wrong that was giving me a syntax error. I assumed it was because I couldn't do what I tried to do above. Thanks for the reply, James.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000