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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 New variable with logic from 2 other fields.

Author  Topic 

stevenc49
Starting Member

14 Posts

Posted - 2008-08-07 : 19:20:46
Hi,

I am trying to create a new variable with a value that is based on two different variables.

I have 2 fields:
1) StoryPoints: (could be any integer)
2) Status: (could be "Open", "Closed" or "Resolved"

I want to make a new field called "RemainingStoryPoints" which would have a value based on the following conditions:
if (Status=="Open")
RemainingStoryPoints = StoryPoints
if (Status=="Closed" OR Status=="Resolved")
RemainingStorypoints = 0

How would I do something like that in SQL?
I'm using SQL Server, so T-SQL, if that helps.

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-08-07 : 20:37:12
use a case statement if it's part of a update, or if you're using in a script then just use a standard IF clause.

Explain more and show a sample of what you want in the right context, and I'll try to give a example.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-08 : 00:43:05
CASE WHEN Status=="Closed" OR Status=="Resolved" THEN 0 ELSE StoryPoints END AS RemainingStorypoints
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-08 : 03:23:01
quote:
Originally posted by visakh16

CASE WHEN Status=="Closed" OR Status=="Resolved" THEN 0 ELSE StoryPoints END AS RemainingStorypoints


Again copy and paste. Use single =

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-08 : 13:16:45
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

CASE WHEN Status=="Closed" OR Status=="Resolved" THEN 0 ELSE StoryPoints END AS RemainingStorypoints


Again copy and paste. Use single =

Madhivanan

Failing to plan is Planning to fail


ah..my bad....thanks for spotting out
Go to Top of Page
   

- Advertisement -