• I notice that you use the data type "text". This data type has been deprecated a long time ago. Please consider replacing it with varchar(max).

    Can you repost the sample data as INSERT statements, please? That should save a lot of people a lot of typing.

    Also, you want to return values such as 1500 and (800 + 1200) that are not even in this table. That's rather hard. If you want SQL Server to return that, then it must be in a table somewhere, not only in an array in your C# or VB.Net code.

    If you want SQL Server to return "something" that you can use in the client code to get the correct final result, then please specify what SQL Server should return. Also clarify exactly how you intend the client to call the database, and in what form the result should be returned to the client (e.g. return parameters, result set, ...)

    This is a SQL Server forum, so we can help you with that part. Ideally, we want to provide code that you can run in a query window and that returns the expected results in the query output pane; you can then lift that code to use it in your C#/VB.Net code.

    Finally, I need more explanation on the results, since the data you posted plus the explanation doesn't help me understand the logic.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/