all groups > sql server programming > september 2006 >
You're in the

sql server programming

group:

Updating tables


Re: Updating tables Arnie Rowland
9/28/2006 12:26:28 PM
sql server programming:
It 'would' be quite convenient to have the table DDL.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


[quoted text, click to view]

Updating tables obelix
9/28/2006 7:13:58 PM
I have three tables: Process_Log, Process_A AND Process_B . The log table is
used to create logs for data inserted in the other two tbls. The two tbls
have the Process_Log ID as an FK and for each of the two a unique process
file ID exists in the Log . I am using these update statements to update the
log with the record count. I want to do this in one statement and possibly
derive wc of the two tbls to use based on the Process_File_ID wc is unique
for each of the two tbls. (I've left out the declarations for convinience
sake)

stmt:
UPDATE Process_Log
SET Imported_Records_Count = (SELECT COUNT(A.iID)
FROM Process_A A
WHERE A.Process_Log_ID = P.iID )
FROM Process_Log P
WHERE P.Process_File_ID = @plFile_ID
------------->
UPDATE Process_Log
SET Imported_Records_Count = (SELECT COUNT(B.iID)
FROM Process_B B
WHERE B.Process_Log_ID = P.iID )
FROM Process_Log P
WHERE P.Process_File_ID = @plFile_ID


Any ideas?

--
obelix

Message posted via http://www.sqlmonster.com
Re: Updating tables Hugo Kornelis
9/30/2006 12:28:14 AM
[quoted text, click to view]

Hi Obelix,

Your convenience or ours?

[quoted text, click to view]

Completely untested (for convenience sake):

UPDATE Process_Log
SET Imported_Records_Count = (SELECT COUNT(A.iID)
FROM Process_A A
WHERE A.Process_Log_ID = P.iID )
+ (SELECT COUNT(B.iID)
FROM Process_B B
WHERE B.Process_Log_ID = P.iID )
FROM Process_Log P
WHERE P.Process_File_ID = @plFile_ID

--
AddThis Social Bookmark Button