By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

if else in select Statement

P: 4
Hi guys, I am new here. I need to put the below if else condition in select statement, is it possible?

if task_is_trunk = 1
(select branch_name from dbo.tblBranch where task_location_guid = dbo.tblBranch.branch_guid) as location_name
else
(select location_id from dbo.tblCSLocation where location_guid = dbo.tblCSTask.task_location_guid) as location_name

Thanks!
Jan 9 '09 #1
Share this Question
Share on Google+
3 Replies


ck9663
Expert 2.5K+
P: 2,878
Your query might return multiple result sets. What are you trying to do with this code?

-- CK
Jan 9 '09 #2

100+
P: 344
I think this would work "correctly".
(select branch_name from dbo.tblBranch where task_location_guid = dbo.tblBranch.branch_guid AND task_is_trunk = 1) as location_name
Union
(select location_id from dbo.tblCSLocation where location_guid = dbo.tblCSTask.task_location_guid AND task_is_trunk <> 1) as location_name
Jan 10 '09 #3

P: 4
thx for ur reply guys, I solved the problem by joining all those tables, and query as below

Expand|Select|Wrap|Line Numbers
  1. SELECT     'location_name' = CASE
  2.                     WHEN t.task_is_trunk = 1 THEN
  3.                         dbo.tblbranch.branch_name
  4.                     ELSE
  5.                         dbo.tblCSLocation.location_id
  6.                     END
Jan 12 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.