
Signature
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
>I have a table that contains multiple numeric rows. I need a VIEW that
>calculates another row displaying the percentages of each numeric row. For
[quoted text clipped - 6 lines]
> the best way of doing this? (I can nearly do it just in a regular query
> but I cannot put all fields into the string)
Sylvain,
I'm trying to use a UDF but it is only returning the last successful test.
For example, if @intGeneralFund is 20,000 and the other 2 variables are
blank, the string returned is "General Fund 20,000", which is correct.
However, if @intGeneralFund is 20,000 and @intDebt is 10,000, the string
returned is "Debt Financing 10,000" (the general fund portion of the string
disappears). Any idea why this would happen?
Also, I cannot do this in a single query because there is so much CAST'ing
and totaling and concatenating of strings, my mind gets boggled! :P
ALTER FUNCTION dbo.pGenerateFundSource (
@intGeneralFund INT = 0,
@intSpecial INT = 0,
@intDebt INT = 0)
RETURNS NVARCHAR(1024)
AS
BEGIN
DECLARE @strTemp NVARCHAR(1024)
DECLARE @strOUT NVARCHAR(1024)
SET @strOUT = N''
IF @intGeneralFund <> 0
BEGIN
SET @strTemp = @strOUT
SET @strOUT = RTRIM(@strTemp) + N'General Fund ' + CAST(@intGeneralFund AS
NVARCHAR(50)) + N' '
END
IF @intSpecial <> 0
BEGIN
SET @strTemp = @strOUT
SET @strOUT = RTRIM(@strTemp) + N'Special Funds ' + CAST(@intSpecial AS
NVARCHAR(50)) + N' '
END
IF @intDebt <> 0
BEGIN
SET @strTemp = @strOUT
SET @strOUT = RTRIM(@strTemp) + N'Debt Financing ' + CAST(@intDebt AS
NVARCHAR(50)) + N' '
END
RETURN @strOUT
END
> Why you cannot put all fields into a string with your regular query?
>
[quoted text clipped - 11 lines]
>> is the best way of doing this? (I can nearly do it just in a regular
>> query but I cannot put all fields into the string)
Ryan Langton - 08 Aug 2005 20:39 GMT
Nevermind, the UDF is working. There just weren't any cases in the database
where there would be more than one value > 0 of those 3 variables!
> Sylvain,
>
[quoted text clipped - 80 lines]
>>> is the best way of doing this? (I can nearly do it just in a regular
>>> query but I cannot put all fields into the string)
Sylvain Lafontaine - 08 Aug 2005 20:51 GMT
Make sure that you don't have any Null value creeping in.

Signature
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
> Nevermind, the UDF is working. There just weren't any cases in the
> database where there would be more than one value > 0 of those 3
[quoted text clipped - 86 lines]
>>>> is the best way of doing this? (I can nearly do it just in a regular
>>>> query but I cannot put all fields into the string)