简体   繁体   中英

SQL Server Reporting Services - Report Expressions Execution

Say I have the following expression:

=DateAdd(DateInterval.Year,-1,Today())

Is there a SQL Server web service endpoint that'll allow me to pass in an expression and return the result of the executed expression? I looked through the endpoints listed here but couldn't find one.

Or is there another way to evaluate this expression?

I've found another way to evaluate the expression using VB.net (This assumes that @Wolfgang Kais is correct about VB.net use instead of VBA)

Here is the code snippet:

using System;
using System.CodeDom.Compiler;
using System.Text;
using Microsoft.VisualBasic;

namespace VbStringCompiler
{
internal class Program
{
    public static void Main(string[] args)
    {
        new Program();
    }

    private const string CRLF = "\r\n";

    private Program()
    {
        var vbCodeProvider = new VBCodeProvider();

        var compilerParameters = new CompilerParameters();
        compilerParameters.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");
        compilerParameters.ReferencedAssemblies.Add("System.dll");
        compilerParameters.CompilerOptions = "/t:library";
        compilerParameters.GenerateInMemory = true;

        var stringBuilder = new StringBuilder();

        stringBuilder.Append("Imports Microsoft.VisualBasic" + CRLF);
        stringBuilder.Append("Imports System" + CRLF + CRLF);

        stringBuilder.Append("Namespace Evaluate" + CRLF);
        stringBuilder.Append("Class RunTime" + CRLF);
        stringBuilder.Append("Public Function Run() As Object" + CRLF);

        // insert code to return
        stringBuilder.Append("Return DateAdd(DateInterval.Year, -1, Today())" + CRLF);

        stringBuilder.Append("End Function" + CRLF);
        stringBuilder.Append("End Class" + CRLF);
        stringBuilder.Append("End Namespace" + CRLF);

        try
        {
            var compilerResults =
                vbCodeProvider.CompileAssemblyFromSource(compilerParameters, stringBuilder.ToString());
            if (compilerResults.Errors.Count > 0)
            {
                foreach (CompilerError compilerError in compilerResults.Errors)
                {
                    Console.Error.WriteLine(compilerError.ToString());
                }

                return;
            }

            var instance = compilerResults.CompiledAssembly.CreateInstance("Evaluate.RunTime");
            var methodInfo = instance.GetType().GetMethod("Run");
            var methodReturn = methodInfo.Invoke(instance, null);

            Console.WriteLine(methodReturn);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.StackTrace);
        }
    }
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM