468,316 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

if else in select Statement

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
3 15876
ck9663
2,878 Expert 2GB
Your query might return multiple result sets. What are you trying to do with this code?

-- CK
Jan 9 '09 #2
Bassem
344 100+
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
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.

Similar topics

7 posts views Thread by Gert Albertse | last post: by
12 posts views Thread by Roman Töngi | last post: by
2 posts views Thread by phaser2001 | last post: by
7 posts views Thread by jcochran | last post: by
8 posts views Thread by Jim Michaels | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.