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.
| Author |
Topic |
|
UnathiM
Starting Member
8 Posts |
Posted - 2006-08-08 : 09:23:40
|
| HiI 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 ' + @DealerEndIf RTrim(LTrim(@BranchType)) in ( 'A' , 'B', 'C', 'D') Begin select @Dealer = dbo.FNDealerByBranch (@Branch) select Dealer = 'Captured By: ' + @DealerEnd 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 |
 |
|
|
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 ' + @DealerEndPrint @dealerMay be the use of the UDF FNDealerByBranch is incorrectSrinika |
 |
|
|
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 |
 |
|
|
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 |
 |
|
|
|
|
|
|
|