User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 423,548 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,928 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 4337 | Replies: 0
Reply
Join Date: May 2006
Posts: 1
Reputation: rhaazy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rhaazy rhaazy is offline Offline
Newbie Poster

UPDATE question for ms sql 2000

  #1  
May 23rd, 2006
I have an app that performs scans and returns information
like what windows updates it has, services running, programs installed,
browsesr history, etc. Scans will be performed once a week and sent to
a server. The server will only save the most recent scan and store the
rest in a history database. I have the methods for inserting and they
work fine. However I am stuck with the task of getting this to work
after a scan from a PC is already stored. The procedure will have to
check the AssetName from tblAsset and compare it to the equivalent in
my XML input. It will get the associated ScanID and use that to make
updates in tblScan and tblScanDetail.
ALTER PROCEDURE csTest.StoredProcedure1 (@doc NTEXT)

AS
declare @iTree int
declare @assetid int
declare @scanid int
create table #temp (ID nvarchar(50), ParentID nvarchar(50), Name
nvarchar(50), scanattribute nvarchar(50))
create table #dup (attid nvarchar(50), name nvarchar (50), ID
nvarchar(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 FROM
tblScanAttribute, #temp
WHERE tblScanAttribute.Name = #temp.Name

INSERT 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, tblScan
WHERE tblScanAttribute.Name = #temp.Name
ORDER BY tblScan.ScanID

drop table #temp
drop table #dup

EXEC sp_xml_removedocument @iTree

RETURN
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 6:02 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC