Sorry for the length of this, I'm trying to give a lot of info to avoid non-relevant solutions.
My goal is to embed at least 1 UPDATE statement into a SELECT statement so that I have a chance to update some computed values at the instant before the select statement runs (think of it like a TRIGGER on SELECT). VIEW is not in immediate solution, since I'm constrained by the system I'm using (see below).
I'm customizing a 3rd party commerical ERP that is weak on features (system will remain nameless! -- upshot is you haven't heard of it, but its not home grown either). It has a canned query facility where I can use a text/GUI to build a SELECT query. Once I save a query, the users can click on the query to execute it and see the results. ERP runs atop MS SQL Server 2000; version upgrade is NOT in the cards right now. I can write whatever feature set I need outside of the ERP in whatever language I want, I have done this in the past, if the features warrant it. But my user community finds it easier when my customizations can be done in the ERP system.
The query can be arbitrarily complex, but the ERP package builds the SQL Select statement itself. Internal to the compiled ERP is something like this (this is just a guess!):
"SELECT " + fieldList + " FROM " + tableListAndJoins + " WHERE " + whereCond
The GUI builder helps novice users build the fieldList and so on but you can bypass it and write the clauses in text as long as the SQL is valid when combined as above.
I can't seem to find an incantation to run a stored procedure as a side effect of a SELECT statement, whether it's in the select clause, where clause, etc. I really don't care how I jailbreak the system -- a stable SQL injection attack would be fine, as long as it didn't mean I had to modify the security of underlying sql server itself. I've looked at UDFs, but you can't put an UPDATE statement into a scalar UDF, and it doesn't make sense to try to modify the return of a table UDF (or does it?). If you can UPDATE from within a VIEW then I would like to see an example, but I realize I can use a VIEW to compute columns and that is not the solution I am looking for. I read a suggestive statement online about being able to use some sort of XP_ to accomplish this, but as to which XP_ or how to do it, I don't know.
this question is NOT a solution, in and of itself: http://stackoverflow.com/questions/545904/updating-a-table-within-a-select-statement