CREATE PROCEDURE dbo.aip_generateviews
AS
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
SET NOCOUNT ON
DECLARE @intReturn int
SET @intReturn = 0
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[allcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[allcomputers]
EXEC ('
CREATE VIEW dbo.allcomputers
AS
SELECT DISTINCT dbo.ai_oldef_prop.userid,
dbo.ai_oldef_prop.orgnm,
dbo.ai_oldef_prop.office,
dbo.ai_oldef_prop.hwsource,
dbo.ai_oldef_prop.region,
dbo.ai_oldef_prop.osname,
dbo.ai_oldef_prop.ossp,
dbo.ai_oldef_prop.osver,
dbo.ai_oldef_prop.ospub,
dbo.ai_oldef_prop.oslanguage,
dbo.ai_oldef_prop.hwuse,
ai_oldef_prop.fssize,
ai_oldef_prop.fsfree,
dbo.ai_oldef_prop.instdate,
dbo.ai_oldef_prop.lscandate,
dbo.ai_hwdef_prop.*,
round(round(convert(decimal(5,2),coreavg/10),0)*10,0) as hwcpuperf
FROM dbo.ai_hwdef_prop
INNER JOIN
dbo.ai_oldef_prop
ON dbo.ai_hwdef_prop.hwuuid = dbo.ai_oldef_prop.hwuuid
LEFT JOIN
ai_hwdef_cpuperf_kpi
ON ai_hwdef_prop.hwuuid = ai_hwdef_cpuperf_kpi.hwuuid
WHERE ai_hwdef_prop.hwname != ''''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on allcomputers to aiadmin
grant delete on allcomputers to aiadmin
grant select on allcomputers to aiadmin
grant update on allcomputers to aiadmin
grant delete on allcomputers to aiadmin
grant insert on allcomputers to aiadmin
grant select on allcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[laptopcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[laptopcomputers]
EXEC ('
CREATE VIEW dbo.laptopcomputers
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers WHERE hwuse=''Laptop''
/*WHERE (hwtype = ''Notebook'')
OR (hwtype = ''Laptop'')
OR (hwtype = ''Portable'')*/
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on laptopcomputers to aiadmin
grant delete on laptopcomputers to aiadmin
grant select on laptopcomputers to aiadmin
grant update on laptopcomputers to aiadmin
grant delete on laptopcomputers to aiadmin
grant insert on laptopcomputers to aiadmin
grant select on laptopcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[desktopcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[desktopcomputers]
EXEC ('
CREATE VIEW dbo.desktopcomputers
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers WHERE hwuse=''Desktop''
/*WHERE (osname NOT LIKE ''%Server%'')
AND (osname NOT LIKE ''%server%'')
AND (osname!=''AIX'')
AND (osname!=''SunOS'')
AND (osname NOT LIKE ''%Linux%'')
AND (osname!=''HP-UX'')
AND ( hwtype IS NULL
OR NOT (hwtype = ''Notebook''
OR hwtype = ''Laptop''
OR hwtype = ''Portable''))*/
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on desktopcomputers to aiadmin
grant delete on desktopcomputers to aiadmin
grant select on desktopcomputers to aiadmin
grant update on desktopcomputers to aiadmin
grant delete on desktopcomputers to aiadmin
grant insert on desktopcomputers to aiadmin
grant select on desktopcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[servercomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[servercomputers]
EXEC ('
CREATE VIEW dbo.servercomputers
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers WHERE hwuse=''Server''
/*WHERE ( (osname LIKE ''%Server'')
OR (osname LIKE ''%Unix%'')
OR (osname LIKE ''%Linux%'')
OR (osname LIKE ''%Server%'')
OR (osname LIKE ''%server%'')
OR (osname=''HP-UX'')
OR (osname=''SunOS'')
OR (osname=''AIX''))
AND ( hwtype IS NULL
OR NOT (hwtype = ''Notebook''
OR hwtype = ''Laptop''
OR hwtype = ''Portable''))*/
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on servercomputers to aiadmin
grant delete on servercomputers to aiadmin
grant select on servercomputers to aiadmin
grant update on servercomputers to aiadmin
grant delete on servercomputers to aiadmin
grant insert on servercomputers to aiadmin
grant select on servercomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[allwinxpsp2]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[allwinxpsp2]
EXEC ('
CREATE VIEW dbo.allwinxpsp2
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE osname like ''Windows XP%'' and ossp=''Service Pack 2''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on allwinxpsp2 to aiadmin
grant delete on allwinxpsp2 to aiadmin
grant select on allwinxpsp2 to aiadmin
grant update on allwinxpsp2 to aiadmin
grant delete on allwinxpsp2 to aiadmin
grant insert on allwinxpsp2 to aiadmin
grant select on allwinxpsp2 to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[allwinnotxpsp2]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[allwinnotxpsp2]
EXEC ('
CREATE VIEW dbo.allwinnotxpsp2
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE osname like ''Windows XP%'' and ossp!=''Service Pack 2''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on allwinnotxpsp2 to aiadmin
grant delete on allwinnotxpsp2 to aiadmin
grant select on allwinnotxpsp2 to aiadmin
grant update on allwinnotxpsp2 to aiadmin
grant delete on allwinnotxpsp2 to aiadmin
grant insert on allwinnotxpsp2 to aiadmin
grant select on allwinnotxpsp2 to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[aiv_usrtoorglast]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[aiv_usrtoorglast]
EXEC ('
CREATE VIEW aiv_usrtoorglast AS SELECT dbo.ai_usrdef_orgtree_prop.pmf as userid,
ud_orgdef_list.olorgname, ud_orgdef_list.olnote, ud_orgdef_list.oldiv
FROM dbo.ai_usrdef_orgtree_prop INNER JOIN
dbo.ud_orgdef_list ON dbo.ai_usrdef_orgtree_prop.reportsto LIKE ''%'' + dbo.ud_orgdef_list.oluserlist
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on aiv_usrtoorglast to aiadmin
grant delete on aiv_usrtoorglast to aiadmin
grant select on aiv_usrtoorglast to aiadmin
grant update on aiv_usrtoorglast to aiadmin
grant delete on aiv_usrtoorglast to aiadmin
grant insert on aiv_usrtoorglast to aiadmin
grant select on aiv_usrtoorglast to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[allorgloccomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[allorgloccomputers]
EXEC ('
CREATE VIEW dbo.allorgloccomputers
AS
SELECT dbo.ai_oldef_prop.userid,
dbo.ai_oldef_prop.orgnm,
dbo.ai_oldef_prop.office,
dbo.ai_oldef_prop.hwsource,
dbo.ai_oldef_prop.region,
dbo.ai_hwdef_prop.hwname,
dbo.ai_hwdef_prop.hwmfgr,
dbo.ai_hwdef_prop.hwproctype,
dbo.ai_hwdef_prop.hwuuid
FROM dbo.ai_hwdef_prop
INNER JOIN
dbo.ai_oldef_prop
ON dbo.ai_hwdef_prop.hwuuid = dbo.ai_oldef_prop.hwuuid
WHERE ai_hwdef_prop.hwname != ''''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on allorgloccomputers to aiadmin
grant delete on allorgloccomputers to aiadmin
grant select on allorgloccomputers to aiadmin
grant update on allorgloccomputers to aiadmin
grant delete on allorgloccomputers to aiadmin
grant insert on allorgloccomputers to aiadmin
grant select on allorgloccomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[appsbycategory]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[appsbycategory]
EXEC ('
CREATE VIEW dbo.appsbycategory
AS
SELECT dbo.ai_swdef_prop.*,
dbo.ai_swcat_prop.scname AS scname,
dbo.ai_swcat_prop.scnote AS scnote
FROM dbo.ai_swdef_prop
INNER JOIN
dbo.ai_swcat_swdef_rel
ON dbo.ai_swdef_prop.swuuid = dbo.ai_swcat_swdef_rel.swuuid
INNER JOIN
dbo.ai_swcat_prop
ON dbo.ai_swcat_swdef_rel.scuuid = dbo.ai_swcat_prop.scuuid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on appsbycategory to aiadmin
grant delete on appsbycategory to aiadmin
grant select on appsbycategory to aiadmin
grant update on appsbycategory to aiadmin
grant delete on appsbycategory to aiadmin
grant insert on appsbycategory to aiadmin
grant select on appsbycategory to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[appsetrust]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[appsetrust]
EXEC ('
CREATE VIEW dbo.appsetrust
AS
SELECT dbo.ai_swdef_prop.swname,
dbo.ai_swdef_hwdef_rel.hwuuid
FROM dbo.ai_swdef_hwdef_rel
INNER JOIN
dbo.ai_swdef_prop
ON dbo.ai_swdef_hwdef_rel.swuuid = dbo.ai_swdef_prop.swuuid
WHERE UPPER(dbo.ai_swdef_prop.swname) like ''%ETRUST ANTIVIRUS%''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on appsetrust to aiadmin
grant delete on appsetrust to aiadmin
grant select on appsetrust to aiadmin
grant update on appsetrust to aiadmin
grant delete on appsetrust to aiadmin
grant insert on appsetrust to aiadmin
grant select on appsetrust to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[hotfixdetailforcomputer]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[hotfixdetailforcomputer]
EXEC ('
CREATE VIEW dbo.hotfixdetailforcomputer
AS
SELECT dbo.ai_hfdef_prop.hfpub,
dbo.ai_hfdef_prop.hfname,
dbo.ai_hfdef_prop.hfsp,
dbo.ai_hfdef_prop.hfid,
dbo.ai_hfdef_prop.hfver,
dbo.ai_hfdef_prop.hfrel,
dbo.ai_hfdef_prop.hfmod,
dbo.ai_hfdef_prop.hfbld,
dbo.ai_hfdef_hwdef_rel.hwuuid
FROM dbo.ai_hfdef_prop
INNER JOIN
dbo.ai_hfdef_hwdef_rel
ON dbo.ai_hfdef_prop.hfuuid = dbo.ai_hfdef_hwdef_rel.hfuuid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on hotfixdetailforcomputer to aiadmin
grant delete on hotfixdetailforcomputer to aiadmin
grant select on hotfixdetailforcomputer to aiadmin
grant update on hotfixdetailforcomputer to aiadmin
grant delete on hotfixdetailforcomputer to aiadmin
grant insert on hotfixdetailforcomputer to aiadmin
grant select on hotfixdetailforcomputer to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[hotfixpubnmsphfcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[hotfixpubnmsphfcomputers]
EXEC ('
CREATE VIEW dbo.hotfixpubnmsphfcomputers
AS
SELECT dbo.allcomputers.*,
dbo.ai_hfdef_hwdef_rel.hfuuid
FROM dbo.allcomputers
RIGHT OUTER JOIN
dbo.ai_hfdef_hwdef_rel
ON dbo.allcomputers.hwuuid = dbo.ai_hfdef_hwdef_rel.hwuuid
WHERE (dbo.allcomputers.hwname <> '''')
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on hotfixpubnmsphfcomputers to aiadmin
grant delete on hotfixpubnmsphfcomputers to aiadmin
grant select on hotfixpubnmsphfcomputers to aiadmin
grant update on hotfixpubnmsphfcomputers to aiadmin
grant delete on hotfixpubnmsphfcomputers to aiadmin
grant insert on hotfixpubnmsphfcomputers to aiadmin
grant select on hotfixpubnmsphfcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[linuxcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[linuxcomputers]
EXEC ('
CREATE VIEW dbo.linuxcomputers
AS
SELECT ospub + '' '' + osname AS osname,
userid,
orgnm,
office,
hwsource,
region,
hwuuid,
hwdom,
hwname,
hwsn,
hwtype,
hwmfgr,
hwmodel,
hwmem,
hwuse,
hwbiosmfgr,
hwbiosver,
hwbiosdate,
hwprocmfgr,
hwprocmodel,
hwproctype,
hwproccount,
hwprocspeed,
fssize,
fsfree,
ospub,
osver,
ossp,
oslanguage,
lscandate,
instdate
FROM dbo.allcomputers
WHERE (osname LIKE ''%Linux%'')
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on linuxcomputers to aiadmin
grant delete on linuxcomputers to aiadmin
grant select on linuxcomputers to aiadmin
grant update on linuxcomputers to aiadmin
grant delete on linuxcomputers to aiadmin
grant insert on linuxcomputers to aiadmin
grant select on linuxcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[locationsum]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[locationsum]
EXEC ('
CREATE VIEW dbo.locationsum
AS
SELECT TOP 200 COUNT(region) AS countofregion,
region
FROM dbo.ai_oldef_prop
GROUP BY region
ORDER BY COUNT(region) DESC, region
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on locationsum to aiadmin
grant delete on locationsum to aiadmin
grant select on locationsum to aiadmin
grant update on locationsum to aiadmin
grant delete on locationsum to aiadmin
grant insert on locationsum to aiadmin
grant select on locationsum to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[notscannedlast30days]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[notscannedlast30days]
EXEC ('
CREATE VIEW dbo.notscannedlast30days
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
INNER JOIN ai_hwdef_lscandate_kpi
ON allcomputers.hwuuid= ai_hwdef_lscandate_kpi.hwuuid
WHERE ( ai_hwdef_lscandate_kpi.lscandate < DATEADD(m, - 1, GETDATE()))
AND osname != ''''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on notscannedlast30days to aiadmin
grant delete on notscannedlast30days to aiadmin
grant select on notscannedlast30days to aiadmin
grant update on notscannedlast30days to aiadmin
grant delete on notscannedlast30days to aiadmin
grant insert on notscannedlast30days to aiadmin
grant select on notscannedlast30days to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[notscannedlast60days]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[notscannedlast60days]
EXEC ('
CREATE VIEW dbo.notscannedlast60days
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
INNER JOIN ai_hwdef_lscandate_kpi
ON allcomputers.hwuuid= ai_hwdef_lscandate_kpi.hwuuid
WHERE (ai_hwdef_lscandate_kpi.lscandate < DATEADD(m, - 2, GETDATE()))
AND osname != ''''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on notscannedlast60days to aiadmin
grant delete on notscannedlast60days to aiadmin
grant select on notscannedlast60days to aiadmin
grant update on notscannedlast60days to aiadmin
grant delete on notscannedlast60days to aiadmin
grant insert on notscannedlast60days to aiadmin
grant select on notscannedlast60days to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[notscannedlast90days]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[notscannedlast90days]
EXEC ('
CREATE VIEW dbo.notscannedlast90days
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
INNER JOIN ai_hwdef_lscandate_kpi
ON allcomputers.hwuuid= ai_hwdef_lscandate_kpi.hwuuid
WHERE (ai_hwdef_lscandate_kpi.lscandate < DATEADD(m, - 3, GETDATE()))
AND osname != ''''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on notscannedlast90days to aiadmin
grant delete on notscannedlast90days to aiadmin
grant select on notscannedlast90days to aiadmin
grant update on notscannedlast90days to aiadmin
grant delete on notscannedlast90days to aiadmin
grant insert on notscannedlast90days to aiadmin
grant select on notscannedlast90days to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[osbuiltlast30days]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[osbuiltlast30days]
EXEC ('
CREATE VIEW dbo.osbuiltlast30days
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (instdate > DATEADD(m, - 1, GETDATE()))
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on osbuiltlast30days to aiadmin
grant delete on osbuiltlast30days to aiadmin
grant select on osbuiltlast30days to aiadmin
grant update on osbuiltlast30days to aiadmin
grant delete on osbuiltlast30days to aiadmin
grant insert on osbuiltlast30days to aiadmin
grant select on osbuiltlast30days to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[osbuiltlast60days]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[osbuiltlast60days]
EXEC ('
CREATE VIEW dbo.osbuiltlast60days
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (instdate > DATEADD(m, - 2, GETDATE()))
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on osbuiltlast60days to aiadmin
grant delete on osbuiltlast60days to aiadmin
grant select on osbuiltlast60days to aiadmin
grant update on osbuiltlast60days to aiadmin
grant delete on osbuiltlast60days to aiadmin
grant insert on osbuiltlast60days to aiadmin
grant select on osbuiltlast60days to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[osbuiltlast90days]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[osbuiltlast90days]
EXEC ('
CREATE VIEW dbo.osbuiltlast90days
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (instdate > DATEADD(m, - 3, GETDATE()))
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on osbuiltlast90days to aiadmin
grant delete on osbuiltlast90days to aiadmin
grant select on osbuiltlast90days to aiadmin
grant update on osbuiltlast90days to aiadmin
grant delete on osbuiltlast90days to aiadmin
grant insert on osbuiltlast90days to aiadmin
grant select on osbuiltlast90days to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[osbuiltthisyear]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[osbuiltthisyear]
EXEC ('
CREATE VIEW dbo.osbuiltthisyear
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (instdate > DATEADD(yyyy, - 1, GETDATE()))
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on osbuiltthisyear to aiadmin
grant delete on osbuiltthisyear to aiadmin
grant select on osbuiltthisyear to aiadmin
grant update on osbuiltthisyear to aiadmin
grant delete on osbuiltthisyear to aiadmin
grant insert on osbuiltthisyear to aiadmin
grant select on osbuiltthisyear to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[osunsupported]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[osunsupported]
EXEC ('
CREATE VIEW dbo.osunsupported
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (osname LIKE ''Windows Me'')
OR (osname LIKE ''Windows 9%'')
OR (osname LIKE ''Windows NT%'')
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on osunsupported to aiadmin
grant delete on osunsupported to aiadmin
grant select on osunsupported to aiadmin
grant update on osunsupported to aiadmin
grant delete on osunsupported to aiadmin
grant insert on osunsupported to aiadmin
grant select on osunsupported to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pmftoorg]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pmftoorg]
EXEC ('
CREATE VIEW dbo.pmftoorg
AS
SELECT dbo.ai_usrdef_orgtree_prop.pmf,
ud_orgdef_list.olorgname,
ud_orgdef_list.olnote,
ud_orgdef_list.oldiv
FROM dbo.ai_usrdef_orgtree_prop
INNER JOIN dbo.ud_orgdef_list
ON dbo.ai_usrdef_orgtree_prop.reportsto LIKE ''%'' + dbo.ud_orgdef_list.oluserlist + ''%''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pmftoorg to aiadmin
grant delete on pmftoorg to aiadmin
grant select on pmftoorg to aiadmin
grant update on pmftoorg to aiadmin
grant delete on pmftoorg to aiadmin
grant insert on pmftoorg to aiadmin
grant select on pmftoorg to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pubappca]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pubappca]
EXEC ('
CREATE VIEW dbo.pubappca
AS
SELECT swuuid
FROM ai_swdef_prop
INNER JOIN ai_pubdef_prop
ON ai_swdef_prop.pubuuid = ai_pubdef_prop.pubuuid
WHERE pubname = ''Computer Associates International''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pubappca to aiadmin
grant delete on pubappca to aiadmin
grant select on pubappca to aiadmin
grant update on pubappca to aiadmin
grant delete on pubappca to aiadmin
grant insert on pubappca to aiadmin
grant select on pubappca to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pubappcamachines]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pubappcamachines]
EXEC ('
CREATE VIEW dbo.pubappcamachines
AS
SELECT DISTINCT hwuuid
FROM ai_swdef_hwdef_rel
INNER JOIN pubappca
ON ai_swdef_hwdef_rel.swuuid = pubappca.swuuid
GROUP
BY ai_swdef_hwdef_rel.hwuuid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pubappcamachines to aiadmin
grant delete on pubappcamachines to aiadmin
grant select on pubappcamachines to aiadmin
grant update on pubappcamachines to aiadmin
grant delete on pubappcamachines to aiadmin
grant insert on pubappcamachines to aiadmin
grant select on pubappcamachines to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pubappcacomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pubappcacomputers]
EXEC ('
CREATE VIEW dbo.pubappcacomputers
AS
SELECT dbo.ai_swdef_hwdef_rel.swuuid,
dbo.ai_swdef_prop.swname, swver, swrel, swmod, swbld, swnote,
dbo.allcomputers.*,
dbo.ai_pubdef_prop.pubname as swpub
FROM dbo.ai_swdef_hwdef_rel
INNER JOIN dbo.allcomputers
ON dbo.ai_swdef_hwdef_rel.hwuuid = dbo.allcomputers.hwuuid
INNER JOIN dbo.ai_swdef_prop
ON dbo.ai_swdef_hwdef_rel.swuuid = dbo.ai_swdef_prop.swuuid
INNER JOIN dbo.ai_pubdef_prop
ON dbo.ai_swdef_prop.pubuuid = dbo.ai_pubdef_prop.pubuuid
AND (pubname=''Computer Associates International, Inc.'' or pubname=''Computer Associates International'' or pubname=''Computer Associates'' or pubname=''CA'' or pubname=''ca'')
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pubappcacomputers to aiadmin
grant delete on pubappcacomputers to aiadmin
grant select on pubappcacomputers to aiadmin
grant update on pubappcacomputers to aiadmin
grant delete on pubappcacomputers to aiadmin
grant insert on pubappcacomputers to aiadmin
grant select on pubappcacomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pubappcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pubappcomputers]
EXEC ('
CREATE VIEW dbo.pubappcomputers
AS
SELECT dbo.ai_swdef_hwdef_rel.swuuid,
dbo.ai_swdef_prop.swname, swver, swrel, swmod, swbld, swnote,
dbo.allcomputers.*,
dbo.ai_pubdef_prop.pubname as swpub
FROM dbo.ai_swdef_hwdef_rel
INNER JOIN dbo.ai_swdef_prop
ON dbo.ai_swdef_hwdef_rel.swuuid = dbo.ai_swdef_prop.swuuid
INNER JOIN dbo.allcomputers
ON dbo.ai_swdef_hwdef_rel.hwuuid = dbo.allcomputers.hwuuid
INNER JOIN dbo.ai_pubdef_prop
ON dbo.ai_swdef_prop.pubuuid = dbo.ai_pubdef_prop.pubuuid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pubappcomputers to aiadmin
grant delete on pubappcomputers to aiadmin
grant select on pubappcomputers to aiadmin
grant update on pubappcomputers to aiadmin
grant delete on pubappcomputers to aiadmin
grant insert on pubappcomputers to aiadmin
grant select on pubappcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pubapplaptops]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pubapplaptops]
EXEC ('
CREATE VIEW dbo.pubapplaptops
AS
SELECT dbo.pubappcomputers.*
FROM dbo.pubappcomputers
WHERE hwuse=''Laptop''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pubapplaptops to aiadmin
grant delete on pubapplaptops to aiadmin
grant select on pubapplaptops to aiadmin
grant update on pubapplaptops to aiadmin
grant delete on pubapplaptops to aiadmin
grant insert on pubapplaptops to aiadmin
grant select on pubapplaptops to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pubappdesktops]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pubappdesktops]
EXEC ('
CREATE VIEW dbo.pubappdesktops
AS
SELECT dbo.pubappcomputers.*
FROM dbo.pubappcomputers
WHERE hwuse=''Desktop''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pubappdesktops to aiadmin
grant delete on pubappdesktops to aiadmin
grant select on pubappdesktops to aiadmin
grant update on pubappdesktops to aiadmin
grant delete on pubappdesktops to aiadmin
grant insert on pubappdesktops to aiadmin
grant select on pubappdesktops to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pubappservers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[pubappservers]
EXEC ('
CREATE VIEW dbo.pubappservers
AS
SELECT dbo.pubappcomputers.*
FROM dbo.pubappcomputers
WHERE hwuse=''Server''
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on pubappservers to aiadmin
grant delete on pubappservers to aiadmin
grant select on pubappservers to aiadmin
grant update on pubappservers to aiadmin
grant delete on pubappservers to aiadmin
grant insert on pubappservers to aiadmin
grant select on pubappservers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storagebot50freespace]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[storagebot50freespace]
EXEC ('
CREATE VIEW dbo.storagebot50freespace
AS
SELECT TOP 50
dbo.servercomputers.*
FROM dbo.servercomputers
WHERE servercomputers.fsfree > 0
ORDER
BY servercomputers.fsfree
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on storagebot50freespace to aiadmin
grant delete on storagebot50freespace to aiadmin
grant select on storagebot50freespace to aiadmin
grant update on storagebot50freespace to aiadmin
grant delete on storagebot50freespace to aiadmin
grant insert on storagebot50freespace to aiadmin
grant select on storagebot50freespace to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storagecomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[storagecomputers]
EXEC ('
CREATE VIEW dbo.storagecomputers
AS
SELECT dbo.ai_fsdef_prop.fsname,
dbo.allcomputers.*
FROM dbo.ai_fsdef_prop
INNER JOIN
dbo.allcomputers
ON dbo.ai_fsdef_prop.hwuuid = dbo.allcomputers.hwuuid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on storagecomputers to aiadmin
grant delete on storagecomputers to aiadmin
grant select on storagecomputers to aiadmin
grant update on storagecomputers to aiadmin
grant delete on storagecomputers to aiadmin
grant insert on storagecomputers to aiadmin
grant select on storagecomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storagedesktopcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[storagedesktopcomputers]
EXEC ('
CREATE VIEW dbo.storagedesktopcomputers
AS
SELECT dbo.storagecomputers.*
FROM dbo.storagecomputers
INNER JOIN
dbo.desktopcomputers
ON dbo.storagecomputers.hwuuid = dbo.desktopcomputers.hwuuid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on storagedesktopcomputers to aiadmin
grant delete on storagedesktopcomputers to aiadmin
grant select on storagedesktopcomputers to aiadmin
grant update on storagedesktopcomputers to aiadmin
grant delete on storagedesktopcomputers to aiadmin
grant insert on storagedesktopcomputers to aiadmin
grant select on storagedesktopcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storagefssum]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[storagefssum]
EXEC ('
CREATE VIEW dbo.storagefssum
AS
SELECT TOP 200
COUNT(dbo.ai_fsdef_prop.fsname) AS countoffilesystem,
dbo.ai_fsdef_prop.fsname,
SUM(dbo.ai_fsdef_prop.fssize) AS sumofdrivesize
FROM dbo.ai_fsdef_prop
GROUP
BY dbo.ai_fsdef_prop.fsname
HAVING (((dbo.ai_fsdef_prop.fsname)<>''''))
ORDER
BY sumofdrivesize DESC
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on storagefssum to aiadmin
grant delete on storagefssum to aiadmin
grant select on storagefssum to aiadmin
grant update on storagefssum to aiadmin
grant delete on storagefssum to aiadmin
grant insert on storagefssum to aiadmin
grant select on storagefssum to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storagefilesystemsum]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[storagefilesystemsum]
EXEC ('
CREATE VIEW dbo.storagefilesystemsum
AS
SELECT TOP 200
COUNT(fsname) AS countoffilesystem,
fsname,
SUM(fssize) AS sumofdrivesize
FROM dbo.ai_fsdef_prop
GROUP
BY fsname
HAVING (fsname <> ''N/A'')
ORDER
BY SUM(fssize) DESC
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on storagefilesystemsum to aiadmin
grant delete on storagefilesystemsum to aiadmin
grant select on storagefilesystemsum to aiadmin
grant update on storagefilesystemsum to aiadmin
grant delete on storagefilesystemsum to aiadmin
grant insert on storagefilesystemsum to aiadmin
grant select on storagefilesystemsum to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storagetopfreespace]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[storagetopfreespace]
EXEC ('
CREATE VIEW dbo.storagetopfreespace
AS
SELECT TOP 500 dbo.servercomputers.*
FROM dbo.servercomputers
ORDER
BY servercomputers.fsfree DESC
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on storagetopfreespace to aiadmin
grant delete on storagetopfreespace to aiadmin
grant select on storagetopfreespace to aiadmin
grant update on storagetopfreespace to aiadmin
grant delete on storagetopfreespace to aiadmin
grant insert on storagetopfreespace to aiadmin
grant select on storagetopfreespace to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storagetop50freespace]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[storagetop50freespace]
EXEC ('
CREATE VIEW dbo.storagetop50freespace
AS
SELECT TOP 50
dbo.servercomputers.*
FROM servercomputers
ORDER
BY servercomputers.fsfree DESC
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on storagetop50freespace to aiadmin
grant delete on storagetop50freespace to aiadmin
grant select on storagetop50freespace to aiadmin
grant update on storagetop50freespace to aiadmin
grant delete on storagetop50freespace to aiadmin
grant insert on storagetop50freespace to aiadmin
grant select on storagetop50freespace to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[unixcomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[unixcomputers]
EXEC ('
CREATE VIEW dbo.unixcomputers
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (osname NOT LIKE ''%Windows%'')
AND (osname NOT LIKE ''%Linux%'')
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on unixcomputers to aiadmin
grant delete on unixcomputers to aiadmin
grant select on unixcomputers to aiadmin
grant update on unixcomputers to aiadmin
grant delete on unixcomputers to aiadmin
grant insert on unixcomputers to aiadmin
grant select on unixcomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[userdirectscomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[userdirectscomputers]
EXEC ('
CREATE VIEW dbo.userdirectscomputers
AS
SELECT dbo.ai_usrdef_prop.samid as pmf,
dbo.ai_usrdef_prop.mgr as reportsto,
dbo.allcomputers.*
FROM dbo.ai_usrdef_prop
INNER JOIN
dbo.allcomputers
ON dbo.ai_usrdef_prop.samid = dbo.allcomputers.userid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on userdirectscomputers to aiadmin
grant delete on userdirectscomputers to aiadmin
grant select on userdirectscomputers to aiadmin
grant update on userdirectscomputers to aiadmin
grant delete on userdirectscomputers to aiadmin
grant insert on userdirectscomputers to aiadmin
grant select on userdirectscomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[userhasreports]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[userhasreports]
EXEC ('
CREATE VIEW dbo.userhasreports
AS
SELECT ai_usrdef_prop.samid as PMF,
ai_usrdef_prop.mgr as reportsto
FROM ai_usrdef_prop
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on userhasreports to aiadmin
grant delete on userhasreports to aiadmin
grant select on userhasreports to aiadmin
grant update on userhasreports to aiadmin
grant delete on userhasreports to aiadmin
grant insert on userhasreports to aiadmin
grant select on userhasreports to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[vmwarecomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[vmwarecomputers]
EXEC ('
CREATE VIEW dbo.vmwarecomputers
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (hwmfgr LIKE ''%VMware%'')
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on vmwarecomputers to aiadmin
grant delete on vmwarecomputers to aiadmin
grant select on vmwarecomputers to aiadmin
grant update on vmwarecomputers to aiadmin
grant delete on vmwarecomputers to aiadmin
grant insert on vmwarecomputers to aiadmin
grant select on vmwarecomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[windowscomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[windowscomputers]
EXEC ('
CREATE VIEW dbo.windowscomputers
AS
SELECT dbo.allcomputers.*
FROM dbo.allcomputers
WHERE (osname LIKE ''Windows%'')
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on windowscomputers to aiadmin
grant delete on windowscomputers to aiadmin
grant select on windowscomputers to aiadmin
grant update on windowscomputers to aiadmin
grant delete on windowscomputers to aiadmin
grant insert on windowscomputers to aiadmin
grant select on windowscomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[userreportscomputers]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[userreportscomputers]
EXEC ('
CREATE VIEW dbo.userreportscomputers
AS
SELECT dbo.ai_usrdef_orgtree_prop.reportsto,
dbo.ai_usrdef_orgtree_prop.pmf,
dbo.allcomputers.*
FROM dbo.ai_usrdef_orgtree_prop
INNER JOIN
dbo.allcomputers
ON dbo.ai_usrdef_orgtree_prop.pmf = dbo.allcomputers.userid
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on userreportscomputers to aiadmin
grant delete on userreportscomputers to aiadmin
grant select on userreportscomputers to aiadmin
grant update on userreportscomputers to aiadmin
grant delete on userreportscomputers to aiadmin
grant insert on userreportscomputers to aiadmin
grant select on userreportscomputers to aipublic
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[appsnotetrust]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[appsnotetrust]
EXEC ('
CREATE VIEW dbo.appsnotetrust
AS
SELECT allcomputers.*
FROM dbo.allcomputers
WHERE hwuuid NOT IN
(SELECT hwuuid
FROM ai_swdef_hwdef_rel
WHERE swuuid IN
(SELECT swuuid
FROM ai_swdef_prop
WHERE UPPER(swname) LIKE ''%ETRUST ANTIVIRUS%''))
')
IF @@ERROR > 0 SET @intReturn = 1
grant insert on appsnotetrust to aiadmin
grant delete on appsnotetrust to aiadmin
grant select on appsnotetrust to aiadmin
grant update on appsnotetrust to aiadmin
grant delete on appsnotetrust to aiadmin
grant insert on appsnotetrust to aiadmin
grant select on appsnotetrust to aipublic
RETURN(@intReturn)
GO