dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersTony John
Minu
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » SQL Server

Evaluate And Execute IF Statement in Formula Editor


Posted Date:     Category: SQL Server    
Author: Member Level: Gold    Points: 50


This article will help you to evaluate if statement in your formula. So application like having formula and we want to evaluate if statement dynamically in that scenario we can use this stored procedure to evaluate if expression. This will meet your following requirement Dynamically Evaluate If or Nested If statement,Expression Evaluation Parser,Formula Editor expression execution,Execution Service for Expression



 


Introduction



Problem : How to evaluate if statement or nested if statement or how we can evaluate particular expression given for calculation or evaluation. In c#.net it is vary difficult to evaluate expression having/with if statement.

Solution : We can use exiting functionality of Sql Server keyword Exec statement by little modification in it while evaluating the expression.


Step 1 Create Stored Procedure



CREATE procedure [dbo].[EvaluateExpression]
@Expression as varchar(1000),
@Result as varchar(500) output
as
BEGIN
Declare @TempTable Table (VariableValue varchar(500))
SET @Expression=(Select replace(@Expression,'==','='))
SET @Expression='if (0=1) Then 0 else ' + @Expression
SET @Expression = replace(@Expression,'Then','Select')
SET @Expression = replace(@Expression,'else','else Select')
SET @Expression = replace(@Expression,'Select if','if')
Insert into @TempTable exec (@Expression);
Select @Result=VariableValue from @TempTable;
END


Step 2 : Execute Stored Procedure



declare @v varchar(1000);
declare @formula as varchar(1000)
set @formula = 'IF(5=5) THEN IF(5=5) Then 10 ELSE 5'
exec [EvaluateExpression] @formula,@Result=@v output
select @v


Note : It will reduce efforts to write new evaluation engine in c# and but still we can pick the right things at right time as per our requirements.





Did you like this resource? Share it with your friends and show your love!


Responses to "Evaluate And Execute IF Statement in Formula Editor"
Author: Ravindra Gaurana    07 Jun 2012Member Level: Gold   Points : 0
Thanks for reading


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: What is cursor in Sql Server and its type?
    Previous Resource: Tool for Formatting Sql Statements or TSQL
    Return to Resources
    Post New Resource
    Category: SQL Server


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Evaluating Formula Expression  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.