home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,537 of 19,505   
   Uri Dimant to All   
   Re: Null parameter to function doesn't s   
   08 Jul 09 12:43:18   
   
   bd9252fa   
   XPost: microsoft.public.sqlserver.server   
   From: urid@iscar.co.il   
      
   Hi   
   --A UDF that doesn't reference a db table   
      
   create function dbo.udf (@t bit)   
      
   returns varchar(100)   
      
   as   
      
   begin   
      
   DECLARE @i AS varchar(10)   
      
   select @i =case when @t is null then 'neither' else 'text' end   
      
   return @i   
      
   end   
      
      
      
   select dbo.udf(1)   
      
   select dbo.udf(null)   
      
      
      
      
      
   "Rotwatcher"  wrote in message   
   news:80a997b6-b1ae-483e-b41e-355dd7b0732f@24g2000yqm.googlegroups.com...   
   >I have a function that takes a bit parameter and returns a text   
   > substitute.  I use it in this kind of operation:   
   >   
   > SELECT dbo.fnReturnYesOrNo(MyTable.BitColumn) AS YesOrNo FROM MyTable   
   >   
   > However, if any values of MyTable.BitColumn are NULL then it returns   
   > NULL instead of 'Neither'.   
   >   
   > I can wrap it in an ISNULL to get the 'Neither' - e.g.   
   >   
   > SELECT ISNULL(dbo.fnReturnYesOrNo(MyTable.BitColumn), 'Neither') AS   
   > YesOrNo FROM MyTable   
   >   
   > Can I "persuade" the function to return 'Neither' if the value of the   
   > input parameter is NULL?   
   >   
   > Thanks   
   >   
   > Edward   
   >   
   > CREATE FUNCTION [dbo].[fnReturnYesOrNo]   
   > (   
   > -- Add the parameters for the function here   
   > @YesNoValue int   
   > )   
   > RETURNS varchar(10)   
   > AS   
   > BEGIN   
   > -- Declare the return variable here   
   > DECLARE @Result varchar(10)   
   >   
   > -- Add the T-SQL statements to compute the return value here   
   > SELECT @Result = CASE @YesNoValue WHEN 1 THEN 'Yes' WHEN 0 THEN 'No'   
   > WHEN NULL THEN 'Neither' WHEN Null THEN 'Neither' END   
   >   
   > -- Return the result of the function   
   > RETURN @Result   
   >   
   > END   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca