HI all;I have an User-defined scalar function. It runs a query to populate a variabale and it returns the variable. I checked the query in the UDF seaparately and it works just fine. However when I call the UDF and pass in my parameters, the return is null.Does anyone have any idea?Here is the stored procedure:ALTER FUNCTION [dbo].[zt_prc_fnNSNsFmNIIN_Get] ( @NIIN varchar(5), @PN varchar(20))RETURNS Varchar(50)ASBEGIN -- Declare the return variable here Declare @NSN varchar(50) Set @NSN = (SELECT Convert(varchar(20), RTRIM(NSN.FSC)) + Convert(varchar(20), RTrim(NSN.NIIN)) NSN FROM TechManual.dbo.ANSNS NSN JOIN TechManual.dbo.AITEMTABLE AIT ON NSN.PRIMARYPARTNUMBER = AIT.PRIMARYPARTNUMBER and NSN.DODIC = AIT.DODIC JOIN TechManual.dbo.PARTNUMBERS PN ON AIT.PRIMARYPARTNUMBER = PN.PRIMARYPARTNUMBER WHERE NSN.NIIN = @NIIN AND PN.PARTNUMBER = @PN) RETURN @NSNEND
Here is my usage of it as well as a check of the query.Select @NIINSelect dbo.zt_prc_fnNSNsFmNIIN_Get('015132378', '850AS911') Set @NSN = (SELECT Convert(varchar(20), RTRIM(NSN.FSC)) + Convert(varchar(20), RTrim(NSN.NIIN)) NSN FROM TechManual.dbo.ANSNS NSN JOIN TechManual.dbo.AITEMTABLE AIT ON NSN.PRIMARYPARTNUMBER = AIT.PRIMARYPARTNUMBER and NSN.DODIC = AIT.DODIC JOIN TechManual.dbo.PARTNUMBERS PN ON AIT.PRIMARYPARTNUMBER = PN.PRIMARYPARTNUMBER WHERE NSN.NIIN = '015132378' AND PN.PARTNUMBER = '850AS911') Select @NSN
The Check code query returns a value of 1377015132378 for @NSN. However the function call returns NULL. No idea why?E.R. Joell MCDBA