if (select count(*) from Queries where QueryKey = "SMS001") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS001","All Personal Computers","Finds all personal computers.","Personal Computer",1)
 END
go

if (select count(*) from Queries where QueryKey = "SMS002") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS002","All Servers","Finds personal computers with the Server system role.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS002",1,"Personal Computer","MICROSOFT|IDENTIFICATION|1.0","SystemRole",9,"Server",0)
 END
go


if (select count(*) from Queries where QueryKey = "SMS003") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS003","Computers by Last User...","Finds personal computers with the specified logon name.  Use the wildcard character (%) to match part of the name.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS003",1,"Personal Computer","MICROSOFT|NETWORK|1.0","LogOn Name",23,"<Prompt(Last user's logon name:)>",0)
 END
go

if (select count(*) from Queries where QueryKey = "SMS004") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS004","Computers by Name...","Finds personal computers with the specified computer name.  Use the wildcard character (%) to match part of the name.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS004",1,"Personal Computer","MICROSOFT|IDENTIFICATION|1.0","Name",23,"<Prompt(Computer name:)>",0)
 END
go

if (select count(*) from Queries where QueryKey = "SMS005") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS005","Computers by Operating System...","Finds personal computers with the specified operating system.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS005",1,"Personal Computer","MICROSOFT|OPERATING_SYSTEM|1.0","Operating System Name",9,"<Prompt(Operating system name:)>",0)
 END
go

if (select count(*) from Queries where QueryKey = "SMS006") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS006","Computers by Processor...","Finds personal computers with the specified processor.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS006",1,"Personal Computer","MICROSOFT|PROCESSOR|1.0","Processor Name",9,"<Prompt(Processor name:)>",0)
 END
go

if (select count(*) from Queries where QueryKey = "SMS007") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS007","Computers by System Type...","Finds personal computers with the specified system type.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS007",1,"Personal Computer","MICROSOFT|IDENTIFICATION|1.0","SystemType",9,"<Prompt(Computer system type:)>",0)
 END
go

if (select count(*) from Queries where QueryKey = "SMS008") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS008","Computers with Nearly Full Disks...","Finds personal computers with disk space in use exceeding the specified percentage.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS008",1,"Personal Computer","MICROSOFT|DISK|1.0","% Disk Full",5,"<Prompt(Disk space in use exceeds (percent):)>",0)
 END
go

if (select count(*) from Queries where QueryKey = "SMS009") = 0
 BEGIN
 Insert into Queries (QueryKey, Name, Comments, Architecture, Lifetime) values
 ("SMS009","Inactive Personal Computers...","Finds personal computers that last scanned for hardware and software before the specified dates.","Personal Computer",1)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS009",1,"Personal Computer","MICROSOFT|WORKSTATION_STATUS|1.0","Last Hardware Scan",30,"<Prompt(Hardware last scanned before date (MM/DD/YY):)>",3)
 Insert into QueryExpressions (QueryKey, OperandNumber, Architecture, AGroup, Attribute, Operator, Value, ExprOpCode) values
 ("SMS009",2,"Personal Computer","MICROSOFT|WORKSTATION_STATUS|1.0","Last Software Scan",30,"<Prompt(Software last scanned before date (MM/DD/YY):)>",0)
 END
go

if (select count(*) from PropertyDisplayGroups where Name = "WinMSD") = 0
 BEGIN
 insert PropertyDisplayGroups (Architecture, Name, GroupOrder) values ("Personal Computer", "WinMSD", 25)
 insert PropertyDisplayUsage (Architecture, GroupName, PaneName, PaneOrder) values ("Personal Computer", "WinMSD", "WinMSD", 0)
 insert PropertyDisplayPanes (Architecture, Name, Method, MethodString1, MethodString2, MethodInt1) values ("Personal Computer", "WinMSD", 3, "smsmsd.dll", "MICROSOFT|SMSMSD|1.0", 0)
 END
go

if (select count(*) from AttributeMap where AttributeName = "LogOn Name" and GroupKey = 1 and ArchitectureKey = 5) = 0
 BEGIN
 insert into AttributeMap (ArchitectureKey,GroupKey,AttributeName,
   CommonSpecificFlag,IsKey,ValueType,ColumnName,Description, MaxColWidth)
   values (5,1,'LogOn Name',2,0,2,'LogOn_Name0','',48)
 END
go

if (select count(*) from syscolumns sc, sysobjects st
    where sc.id = st.id and st.name = 'Identification_SPEC' and
    sc.name = 'LogOn_Name0') = 0
 BEGIN
 alter table Identification_SPEC add LogOn_Name0 varchar(48) NULL
 END
go

if (select count(*) from GroupMap where GroupName = 'Network') > 0
 BEGIN
 update Identification_SPEC set
   i.LogOn_Name0 = n.LogOn_Name0
   from Identification_SPEC i,
   Network_COMM n,
   MachineDataTable m1,
   MachineDataTable m2
   where m1.dwMachineID = m2.dwMachineID
   and i.datakey = m1.SpecificKey
   and n.datakey = m2.CommonKey
   and m1.GroupKey = 1
   and m2.GroupKey = (select GroupKey from GroupMap where GroupName = 'Network' and ArchitectureKey = 5)
   and m1.ArchitectureKey = 5
   and m2.ArchitectureKey = 5
 END
go

if (select si.name from sysindexes si, sysobjects so 
    where si.id = so.id and so.name = 'Identification_SPEC' and
    si.name = 'LogOn_Name_idx') = NULL
  BEGIN
  create index LogOn_Name_idx on Identification_SPEC (LogOn_Name0)
  END
go