tsql - T-SQL looping to create a recordset -
I have some stored procedures that I need to write against a dirty animal in a database. Requires a loop through and using the application table from the application table, draw the value out of the other tables (some concurrent / average / etc values).
I have so far:
declare the app to declare the app cursor to select IID by clicking on the OPEN app FETCH from the app @ID on the ID WHILE @@ FETCH_STATUS = 0 start a.NAME_LAST, a.NAME_FIRST, ca.status, (SELECT AVG (number) WHERE application_id = @id from review, (SELECT count (*) WHERE application_id = @id from review) application One from, committee_apps where are the applications Aapplication_id = ca.application_id and a.application_id = @id FETCH next app add-off app apple app deluxe app
The results I want from the app, but I'm sure There's a cleaner way, and I do not think it's a better way to do it correctly than to jump in a mental manner today, because it sounds really ugly for me.
In addition, it seems that I would like to store these values in a temporary table, then select
thanks.
"text">
Deleting a cursor will probably slow down the use of the generated table By doing so, you can get the count and the average with a query and you can join the other table to get the remaining columns. Like this ....
Select one. NAME_LAST, a.NAME_FIRST, ca.status, score Average Ascor, Score. The number of applications from the user. An Internal Insert Committee- on ApplicationsApplication_ID = CA. Join Application_id Left (select application_id, average) score as score (score); Count as review from group (*) by CountScore as application_id) score as a.application_id = scores.application_id
Comments
Post a Comment