DbFunctionCall against typedlist

Posts   
 
    
Stuartt
User
Posts: 1
Joined: 09-Feb-2010
# Posted on: 09-Feb-2010 16:13:35   

Hi,

I have a typedlist which i need to include a function in. I have included the current SQL function Below. Is it possible to covert this into a dbFunctionCall within code ? as i cannot call this function direct from SQL (long story). All the required fields are within the typedlist.

This function takes 3 arguments, Date1, Date2 and Requested(Bool). Based on the login below and the supplied parameters Date1 gets set.

Any help would be appreciated.

Thanks Stuart

BEGIN

DECLARE @ReturnVal AS datetime

IF @Date1 IS NULL BEGIN IF @Requested=0 SET @ReturnVal=@Date2-21 ELSE SET @ReturnVal=@Date2 END ELSE SET @ReturnVal=@Date1

RETURN @ReturnVal END

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 09-Feb-2010 22:40:29   

Something along the lines of


fields[1].ExpressionToApply = new DbFunctionCall(
    "CASE {0} WHEN 0 THEN {1}-21 ELSE {1} END", 
    new object[] { xxxFields.Requested,xxxFields.Date2 });

should get you started.

You can nest function expressions to handle the Date1==null

Matt