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 2000 Forums
 Transact-SQL (2000)
 Help with If statement

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-04-13 : 08:30:58
Hi i just want to make sure my If statement is correct.

Here is what i want it to do :-

(if Solve = T and ServiceEvent = f and Cancelled = F and PartsOrder = F and CRUOrder = F)
or
( if Solve = T and ServiceEvent = t and Cancelled = T and )

then Solve_ind is true else it false

Here is the function i've written, can someone please make sure it correct, i've testing the outter if statement but i do not know a way of testing the inner if statement

CREATE FUNCTION dbo.udf_Voy_Solve_ind(@Solve char(2),@ServiceEvent char(2),@cancelled char(2), @PartsOrder char(2), @CRUOrder char(2))
RETURNS tinyint
AS

BEGIN

DECLARE @Solve_ind tinyint

If @Solve = 'T' and @ServiceEvent = 'F' and @Cancelled = 'F' and @PartsOrder = 'F' and @CRUOrder = 'F'
Begin
IF @Solve = 'T' and @ServiceEvent = 'T' and @Cancelled = 'T'
Begin
Set @Solve_ind = 1
End
Else
Set @Solve_ind = 0

Set @Solve_ind = 1

End
Else
Set @Solve_ind = 0
RETURN @Solve_ind
END


To test it i just used a select statement like this :
select dbo.udf_Voy_Solve_ind('T','F','F','F','F')

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-04-13 : 08:53:18
[code]CREATE FUNCTION dbo.udf_Voy_Solve_ind(@Solve char(2),@ServiceEvent char(2),@cancelled char(2), @PartsOrder char(2), @CRUOrder char(2))
RETURNS tinyint
AS

BEGIN

DECLARE @Solve_ind tinyint

If ( @Solve = 'T' and @ServiceEvent = 'F' and @Cancelled = 'F' and @PartsOrder = 'F' and @CRUOrder = 'F' ) OR
( @Solve = 'T' and @ServiceEvent = 'T' and @Cancelled = 'T')
Begin
Set @Solve_ind = 1
End
Else
Begin
Set @Solve_ind = 0
End


RETURN @Solve_ind
END[/code]

Srinika
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-04-13 : 09:07:48
Thanks Srinika.
Go to Top of Page
   

- Advertisement -