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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Want to write a case within select comparing other
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

536 Posts

Posted - 12/07/2012 :  13:58:03  Show Profile  Reply with Quote
Want to write a case within select comparing other column within the select statement:

Is this the right way both fields are numeric fields:

CASE
WHEN P_P_R.PRSNL_PERSON_ID = prsnl_al.alias then 1
ELSE 2
END as PCP


Thanks a lot for the helpful info.

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/07/2012 :  14:05:01  Show Profile  Reply with Quote
Assuming you want to return 1 when column PRSNL_PERSON_ID in table (or table alias) P_P_R has the same value as column "alias" in table (or table alias) prsnl_al it is correct. If the two columns are not equal, or if one or both of them are null, you will get 2.
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