Question

I have a report writer that will allow me to query my db directly, however the query has to select from a SQL view. I have to develop a lot tracking solution but because of the logic involved, the only way I have been able to accomplish this so far is to hijack the SQL statement before it leaves the report writer and point it towards a function (instead of the view).

I need to develop a more user friendly way to accomplish this. My first though was to populate the view that the report writer sees with an item and lot number from one of my tables, call my function with the item and lot number and then somehow append the original view with usage and consumption transactions for that item/lot. Because of how the report writer is designed, the original view that returns just the item/lot must be the same object as the view that is eventually populated with the transactions.

Is there a way to use an alter view statement as part of a query? Is there a better way to accomplish this goal? I am a bit lost here.

Was it helpful?

Solution

Well not having the reputation to comment, and seeing that this is SQL Server could you do the following?:

SELECT st.*
, dbo.ufn_usage_and_consumption(st.item_number, st.lot_number)
from some_table st

Basically, you are calling both the view and FOR EACH ROW of the view, calling the SQL Server Function.

Please note that this is NOT OPTIMAL. You are essentially doing RBAR processing (Row by Agonizing Row) and calling the function for every row.

Really, I would see about creating a stored procedure, if your report writer supports that and pass parameters to call the query and pass results back.

I'm making the following assumption: 1) the data coming back from the function is a scalar (one value only), if it's not you can return it as a comma delimitted string

Don't know if that helps or not but good luck with your query!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top