Hi,
I would like to know what the best approach is to return a table based on a condition.
For example i have a table which has current orders, let's call it ORDERS_CURRENT.
I have another table with the same signature called ORDERS_HISTORY.
Now when i need to retrieve orders i can do this:
SELECT *
FROM ORDERS_CURRENT
WHERE [PARAMETER] = [VALUE_CURRENT]
UNION
SELECT *
FROM ORDERS_HISTORY
WHERE [PARAMETER = [VALUE_HISTORY]
where parameter is the parameter passed to the procedure and VALUE is the value of the parameter which determins if we need current orders or orders from the history table.
What I would like is something like
SELECT *
FROM GetOrderTable([VALUE])
The function then determines based on the [VALUE] which table to return. This makes for much cleaner code plus I don't have to duplicate the query.
What I could do is create a ORDER record type and ORDERS collection type which is returned by the function but I do not know what the best approach is performance wise. Plus it would be nice if I didn't have to create a type because if the number of fields in the table or query changes i have to update the type accordingly.
Anyone any suggestions what the best approach should be?
t.i.a.,
ratjetoes.
I would like to know what the best approach is to return a table based on a condition.
For example i have a table which has current orders, let's call it ORDERS_CURRENT.
I have another table with the same signature called ORDERS_HISTORY.
Now when i need to retrieve orders i can do this:
SELECT *
FROM ORDERS_CURRENT
WHERE [PARAMETER] = [VALUE_CURRENT]
UNION
SELECT *
FROM ORDERS_HISTORY
WHERE [PARAMETER = [VALUE_HISTORY]
where parameter is the parameter passed to the procedure and VALUE is the value of the parameter which determins if we need current orders or orders from the history table.
What I would like is something like
SELECT *
FROM GetOrderTable([VALUE])
The function then determines based on the [VALUE] which table to return. This makes for much cleaner code plus I don't have to duplicate the query.
What I could do is create a ORDER record type and ORDERS collection type which is returned by the function but I do not know what the best approach is performance wise. Plus it would be nice if I didn't have to create a type because if the number of fields in the table or query changes i have to update the type accordingly.
Anyone any suggestions what the best approach should be?
t.i.a.,
ratjetoes.