•
•
•
•
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 427,764 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,672 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: 4369 | Replies: 0
![]() |
•
•
Join Date: May 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- help with paging in sql 2000 (MS SQL)
- Applying SSL certificate to SQL 2000 (MS SQL)
- Coldfusion use SQL 2000 (ColdFusion)
- In which (really) important ways is SQL 2000 better than Access 2003? (MS SQL)
- VB and MS-sql 2000 data navigation (Visual Basic 4 / 5 / 6)
- Ms Sql 2000 (MS SQL)
Other Threads in the MS SQL Forum
- Previous Thread: HELP - Invalid object error related to sqlole null bug in MSSQL 2000
- Next Thread: Displaying a certain number of records


Linear Mode