SQL Server Forums
Profile | Register | 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?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

DaveBF
Yak Posting Veteran

84 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

3555 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

84 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  
 New 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