Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rhaazy
Starting Member
3 Posts |
Posted - 2006-05-23 : 13:51:37
|
| I have an app that performs scans and returns informationlike what windows updates it has, services running, programs installed,browsesr history, etc. Scans will be performed once a week and sent toa server. The server will only save the most recent scan and store therest in a history database. I have the methods for inserting and theywork fine. However I am stuck with the task of getting this to workafter a scan from a PC is already stored. The procedure will have tocheck the AssetName from tblAsset and compare it to the equivalent inmy XML input. It will get the associated ScanID and use that to makeupdates in tblScan and tblScanDetail.ALTER PROCEDURE csTest.StoredProcedure1 (@doc NTEXT)ASdeclare @iTree intdeclare @assetid intdeclare @scanid intcreate table #temp (ID nvarchar(50), ParentID nvarchar(50), Namenvarchar(50), scanattribute nvarchar(50))create table #dup (attid nvarchar(50), name nvarchar (50), IDnvarchar(50)) /* SET NOCOUNT ON */ EXEC sp_xml_preparedocument @iTree OUTPUT, @doc INSERT INTO tblAsset (AssetName, DatelastScanned, LastModified) SELECT *, LastModified = getdate() FROM openxml(@iTree,'ComputerScan', 1) WITH ( ComputerName nvarchar(30) 'computer/ComputerName', DatelastScanned smalldatetime 'scanheader/ScanDate' ) set @assetid = scope_identity() INSERT INTO tblScan (AssetName, ScanDate, AssetID, LastModified) SELECT *, @assetid, LastModified = getdate() FROM openxml(@iTree,'ComputerScan', 1) WITH ( ComputerName nvarchar(30) 'computer/ComputerName', ScanDate smalldatetime 'scanheader/ScanDate' ) SET @scanid = scope_identity() INSERT INTO #temp SELECT * FROM openxml(@iTree,'ComputerScan/scans/scan/scanattributes/scanattribute', 1) WITH( ID nvarchar(50) './@ID', ParentID nvarchar(50) './@ParentID', Name nvarchar(50) './@Name', scanattribute nvarchar(50) '.' ) INSERT INTO #dup SELECT ScanAttributeID, #temp.scanattribute, #temp.ID FROMtblScanAttribute, #temp WHERE tblScanAttribute.Name = #temp.NameINSERT INTO tblScanDetail(Instance, ScanAttributeID, ScanID,AttributeValue, LastModified)SELECT instance = (select count(*) from #dup where #dup.attid =tblScanAttribute.ScanAttributeID AND ((#dup.name<#temp.scanattribute) or (#dup.name=#temp.scanattribute) and(#dup.ID<=#temp.ID))), tblScanAttribute.ScanAttributeID, tblScan.ScanID, #temp.scanattribute,getdate()FROM tblScanAttribute, #temp, tblScanWHERE tblScanAttribute.Name = #temp.NameORDER BY tblScan.ScanIDdrop table #tempdrop table #dupEXEC sp_xml_removedocument @iTreeRETURN |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-05-24 : 02:57:50
|
| elaborate on why your code is not working, any error messages?by reading what you described, you may need to verify if the scan is already doneif exists or a where clause probably should do itHTH--------------------keeping it simple... |
 |
|
|
|
|
|
|
|