A,B,C and D are sqlserver table columns, can i send this formula to sql to execute and get back the result? if those columns are Date or DateTime columns then can manipulate with fixed date values for example "[A]-getdate()" or "[A] + [21-May-2016 05:00:00
PM]"

first here I think that fetching the value from database into Asp.net and then perform calculation is the easiest solution for this requirement.

you had mentioned that you don't have any problem regarding calculating integer but you have problem with dates.

but you did not post any code. so here we don't know exactly that how you are trying to calculate this formula.

whether you are trying to calculate in sql or in Asp.net.

where you stuck in the code. did you got any error or exception?

please let us know so that we can try to suggest you appropriate suggestion.

otherwise we just try to assume the situation and give the suggestion. which not work always.

Regards

Deepak

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Member

10 Points

150 Posts

## calculate formula

Aug 28, 2016 12:37 PM|sivapooja|LINK

Hi how to calculate our own formula

for example

formulaTxt = "A+B*((C-D)/(A-D))"

A,B,C and D are sqlserver table columns, can i send this formula to sql to execute and get back the result? if those columns are Date or DateTime columns then can manipulate with fixed date values for example "[A]-getdate()" or "[A] + [21-May-2016 05:00:00 PM]"

All-Star

21323 Points

4519 Posts

## Re: calculate formula

Aug 29, 2016 05:59 AM|sreejukg|LINK

You can write a stored procedure in SQL Server that accepts these parameters and return the result.

or

You can retrieve the values from SQL Server and perform the calculation in your code.

My Blog

Member

10 Points

150 Posts

## Re: calculate formula

Aug 29, 2016 12:09 PM|sivapooja|LINK

integer column no issue but if date columns how to perform the calculation

for example

formula = "(([A] - [B]) + ([C] - [D]))"

All-Star

122306 Points

9728 Posts

Moderator

## Re: calculate formula

Aug 29, 2016 01:27 PM|limno|LINK

You need to use dateadd and datediff functions.

Format your SQL query with instant sql formatter:

http://www.dpriver.com/pp/sqlformat.htm

Member

564 Points

240 Posts

## Re: calculate formula

Aug 31, 2016 09:14 AM|balu.devara|LINK

hi,

using datediff you can calculate difference b/w 2 dates like bellow,

SELECT DATEDIFF(day,'2014-08-05','2014-06-05') AS DiffDate

thanks,

murali

Member

196 Points

58 Posts

## Re: calculate formula

Aug 31, 2016 09:33 AM|techviju|LINK

Hi,

create a scalar value function for the formula and call that when you required.Thanks

Vijay

Contributor

2810 Points

1164 Posts

## Re: calculate formula

Sep 13, 2016 05:27 AM|Deepak Panchal|LINK

Hi sivapooja,

first here I think that fetching the value from database into Asp.net and then perform calculation is the easiest solution for this requirement.

you had mentioned that you don't have any problem regarding calculating integer but you have problem with dates.

but you did not post any code. so here we don't know exactly that how you are trying to calculate this formula.

whether you are trying to calculate in sql or in Asp.net.

where you stuck in the code. did you got any error or exception?

please let us know so that we can try to suggest you appropriate suggestion.

otherwise we just try to assume the situation and give the suggestion. which not work always.

Regards

Deepak

Please remember to click "Mark as Answer" the responses that resolved your issue.

If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.