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
 SQL Server Development (2000)
 If Statements

Author  Topic 

UnathiM
Starting Member

8 Posts

Posted - 2006-08-08 : 09:23:40
Hi

I am trying to create a header for a letter based on the type of branch. The following is an If statement that I have written so far.


If RTrim(LTrim(@BranchType)) in ('X','Y')
Begin
select @Dealer = dbo.FNDealerByBranch (@Branch)
select @Dealer = 'Dear ' + @Dealer
End

If RTrim(LTrim(@BranchType)) in ( 'A' , 'B', 'C', 'D')
Begin
select @Dealer = dbo.FNDealerByBranch (@Branch)
select Dealer = 'Captured By: ' + @Dealer
End

This statement does not seem to be working properly because it returns a blank line. Please advise

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-08-08 : 10:04:40
the query looks ok. Verify the value of @BranchType by doing a PRINT


KH

Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-08 : 10:06:02
Check the following :

Declare @BranchType varchar(10), @Dealer varchar(100)

Set @BranchType = 'Y'
Set @Dealer = 'Y_Dealer'

If RTrim(LTrim(@BranchType)) in ('X','Y')
Begin
--select @Dealer = dbo.FNDealerByBranch (@Branch)
select @Dealer = 'Dear ' + @Dealer
End
Print @dealer


May be the use of the UDF FNDealerByBranch is incorrect

Srinika
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-08-08 : 10:09:03
What's the function doing? What type is your test case? ('x', 'y', etc.?) I'm assuming this isn't a direct copy and paste of your code as
quote:
select Dealer = 'Captured By: ' + @Dealer
seems to be missing an '@'. Also, there's no point including
quote:
select @Dealer = dbo.FNDealerByBranch (@Branch)
in the conditional logic, as it is the same for both branches. It's hard to say without seeing what it's doing, but it strikes me that, if you're going to use a function, you should probably include this logic within it, and just get it to spit out a complete string.

Mark
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-08-08 : 12:26:56
Try this:

select
@Dealer =
case
when RTrim(LTrim(@BranchType)) in ('X','Y')
then 'Dear '
when RTrim(LTrim(@BranchType)) in ('A','B','C','D')
then 'Captured By: '
else ''
end+
isnull(dbo.FNDealerByBranch (@Branch),'')







CODO ERGO SUM
Go to Top of Page
   

- Advertisement -