jenny30534
MIS
I need some help guys, one of our developers is running this query against our database, and it keeps crashing our server, other queries, packages, etc. work with no issue. Can anyone see something that may be causing the issue?? Thanks. Our server is running SQL 2000 service pack 4
Jennifer
--SMAN850P SUMMARY VALIDATION FOR SQLBPDETAIL TABLES VS SMAN850P----------------------------------
--
--
DECLARE @FROM_DATE CHAR (8),
@TO_DATE CHAR (8),
@PERIOD CHAR (3),
@YEAR CHAR (4)
--------------------------------
SET @PERIOD ='MAR'
SET @YEAR ='2006'
SET @FROM_DATE ='12/31/05'
SET @TO_DATE ='03/10/06'
--------------------------------
PRINT @PERIOD+' FROM '+@FROM_DATE+' TO '+@TO_DATE
--/*
DROP TABLE #SQLBPD
SELECT * INTO #SQLBPD FROM SQLBPDETAIL
WHERE REC_CODE NOT IN ('A','C') AND
(CONVERT(DATETIME,inv_date) >= CONVERT(DATETIME,@FROM_DATE) AND
CONVERT(DATETIME,inv_date) <= CONVERT(DATETIME,@TO_DATE))
--SMAN MTD BELOW THE SUBTOTAL LINE IN SMAN850P
DROP TABLE #SQLBPD2
SELECT * INTO #SQLBPD2 FROM SQLBPDETAIL
WHERE (CONVERT(DATETIME,INV_DATE) >= CONVERT(DATETIME,@FROM_DATE) AND
CONVERT(DATETIME,INV_DATE) <= CONVERT(DATETIME,@TO_DATE))
DROP TABLE #SQLBPT
SELECT * INTO #SQLBPT FROM SQLBPTOTALS
WHERE (CONVERT(DATETIME,DATE) >= CONVERT(DATETIME,@FROM_DATE) AND
CONVERT(DATETIME,DATE) <= CONVERT(DATETIME,@TO_DATE))
--*/
----------------------------------------------------------------------------------------------
--PASSENGER
DROP TABLE #TOTALSMAN
SELECT '01' AS 'LINE','PASSENGER ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
INTO #TOTALSMAN
FROM #sqlbpd WHERE GRP = '01'
--LIGHT TRUCK
INSERT INTO #TOTALSMAN
SELECT '02' AS 'LINE','LIGHT TRUCK ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP = '11'
--LARGE TRUCK
INSERT INTO #TOTALSMAN
SELECT '03' AS 'LINE','LARGE TRUCK ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP = '22'
--FARM
INSERT INTO #TOTALSMAN
SELECT '04' AS 'LINE','FARM ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('35')
--SPECIALTY RUBBER
INSERT INTO #TOTALSMAN
SELECT '05' AS 'LINE','SPECIALTY RUBBER ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('30','31','38','40','43','51','89')
--EQUIPMENT
INSERT INTO #TOTALSMAN
SELECT '06' AS 'LINE','EQUIPMENT ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('60','63')
--TOOLS/SM EQ
INSERT INTO #TOTALSMAN
SELECT '07' AS 'LINE','TOOLS / SM EQ ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP = '65'
--SUPPLIES
INSERT INTO #TOTALSMAN
SELECT '08' AS 'LINE','SUPPLIES ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('69','73') OR (GRP='93' AND VENDOR='890')
--WHEEL PRODUCTS
INSERT INTO #TOTALSMAN
SELECT '09' AS 'LINE','WHEEL PRODUCTS ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('53','54','55','56')
--NATL ACCT COMM
INSERT INTO #TOTALSMAN
SELECT '10' AS 'LINE','NATL ACCT COMM ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP ='45'
--PART PRODUCTS
INSERT INTO #TOTALSMAN
SELECT '11' AS 'LINE','PART PRODS ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP ='75'
--SUB TOTAL
INSERT INTO #TOTALSMAN
SELECT '12' AS 'LINE',' SUB-TOTAL',SUM(CONVERT(INTEGER,QTY)),SUM(SALES)
FROM #TOTALSMAN
--MISC GRPS 98 & 99
INSERT INTO #TOTALSMAN
SELECT '13' AS 'LINE','MISC GRPS 98 & 99 ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE GRP IN ('98','99') AND REC_CODE NOT IN ('A','C')
AND PRODUCT <> '995000800'
--CR/DSC/ADJ
INSERT INTO #TOTALSMAN
SELECT '14' AS 'LINE','CR/DSC/ADJ ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE REC_CODE IN ('A','C') AND REASON NOT IN ('18','19','20')
AND PRODUCT <> '995000800'
--FET - ADJ
INSERT INTO #TOTALSMAN
SELECT '15' AS 'LINE','FET - ADJ ' as 'CATEGORY','0',
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE PRODUCT = '995000800'
--ROAD HAZARD FEE
INSERT INTO #TOTALSMAN
SELECT '16' AS 'LINE','ROAD HAZARD FEE ' as 'CATEGORY','0',
sum(CONVERT(MONEY,ROAD_HAZARD))as 'SALES'
FROM #sqlbpt
--ROAD HAZARD ADJ
INSERT INTO #TOTALSMAN
SELECT '17' AS 'LINE','ROAD HAZARD ADJ ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE REC_CODE IN ('A','C')
AND REASON IN ('18','19','20')
AND PRODUCT <> '995000800'
--GRAND TOTAL
INSERT INTO #TOTALSMAN
SELECT '18' AS 'LINE',' GRAND-TOTAL',SUM(CONVERT(INTEGER,QTY)),SUM(SALES)
FROM #TOTALSMAN WHERE CONVERT(INTEGER,LINE)>11
SELECT * FROM #TOTALSMAN ORDER BY LINE
Jennifer
--SMAN850P SUMMARY VALIDATION FOR SQLBPDETAIL TABLES VS SMAN850P----------------------------------
--
--
DECLARE @FROM_DATE CHAR (8),
@TO_DATE CHAR (8),
@PERIOD CHAR (3),
@YEAR CHAR (4)
--------------------------------
SET @PERIOD ='MAR'
SET @YEAR ='2006'
SET @FROM_DATE ='12/31/05'
SET @TO_DATE ='03/10/06'
--------------------------------
PRINT @PERIOD+' FROM '+@FROM_DATE+' TO '+@TO_DATE
--/*
DROP TABLE #SQLBPD
SELECT * INTO #SQLBPD FROM SQLBPDETAIL
WHERE REC_CODE NOT IN ('A','C') AND
(CONVERT(DATETIME,inv_date) >= CONVERT(DATETIME,@FROM_DATE) AND
CONVERT(DATETIME,inv_date) <= CONVERT(DATETIME,@TO_DATE))
--SMAN MTD BELOW THE SUBTOTAL LINE IN SMAN850P
DROP TABLE #SQLBPD2
SELECT * INTO #SQLBPD2 FROM SQLBPDETAIL
WHERE (CONVERT(DATETIME,INV_DATE) >= CONVERT(DATETIME,@FROM_DATE) AND
CONVERT(DATETIME,INV_DATE) <= CONVERT(DATETIME,@TO_DATE))
DROP TABLE #SQLBPT
SELECT * INTO #SQLBPT FROM SQLBPTOTALS
WHERE (CONVERT(DATETIME,DATE) >= CONVERT(DATETIME,@FROM_DATE) AND
CONVERT(DATETIME,DATE) <= CONVERT(DATETIME,@TO_DATE))
--*/
----------------------------------------------------------------------------------------------
--PASSENGER
DROP TABLE #TOTALSMAN
SELECT '01' AS 'LINE','PASSENGER ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
INTO #TOTALSMAN
FROM #sqlbpd WHERE GRP = '01'
--LIGHT TRUCK
INSERT INTO #TOTALSMAN
SELECT '02' AS 'LINE','LIGHT TRUCK ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP = '11'
--LARGE TRUCK
INSERT INTO #TOTALSMAN
SELECT '03' AS 'LINE','LARGE TRUCK ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP = '22'
--FARM
INSERT INTO #TOTALSMAN
SELECT '04' AS 'LINE','FARM ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('35')
--SPECIALTY RUBBER
INSERT INTO #TOTALSMAN
SELECT '05' AS 'LINE','SPECIALTY RUBBER ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('30','31','38','40','43','51','89')
--EQUIPMENT
INSERT INTO #TOTALSMAN
SELECT '06' AS 'LINE','EQUIPMENT ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('60','63')
--TOOLS/SM EQ
INSERT INTO #TOTALSMAN
SELECT '07' AS 'LINE','TOOLS / SM EQ ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP = '65'
--SUPPLIES
INSERT INTO #TOTALSMAN
SELECT '08' AS 'LINE','SUPPLIES ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('69','73') OR (GRP='93' AND VENDOR='890')
--WHEEL PRODUCTS
INSERT INTO #TOTALSMAN
SELECT '09' AS 'LINE','WHEEL PRODUCTS ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP IN ('53','54','55','56')
--NATL ACCT COMM
INSERT INTO #TOTALSMAN
SELECT '10' AS 'LINE','NATL ACCT COMM ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP ='45'
--PART PRODUCTS
INSERT INTO #TOTALSMAN
SELECT '11' AS 'LINE','PART PRODS ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd WHERE GRP ='75'
--SUB TOTAL
INSERT INTO #TOTALSMAN
SELECT '12' AS 'LINE',' SUB-TOTAL',SUM(CONVERT(INTEGER,QTY)),SUM(SALES)
FROM #TOTALSMAN
--MISC GRPS 98 & 99
INSERT INTO #TOTALSMAN
SELECT '13' AS 'LINE','MISC GRPS 98 & 99 ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE GRP IN ('98','99') AND REC_CODE NOT IN ('A','C')
AND PRODUCT <> '995000800'
--CR/DSC/ADJ
INSERT INTO #TOTALSMAN
SELECT '14' AS 'LINE','CR/DSC/ADJ ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE REC_CODE IN ('A','C') AND REASON NOT IN ('18','19','20')
AND PRODUCT <> '995000800'
--FET - ADJ
INSERT INTO #TOTALSMAN
SELECT '15' AS 'LINE','FET - ADJ ' as 'CATEGORY','0',
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE PRODUCT = '995000800'
--ROAD HAZARD FEE
INSERT INTO #TOTALSMAN
SELECT '16' AS 'LINE','ROAD HAZARD FEE ' as 'CATEGORY','0',
sum(CONVERT(MONEY,ROAD_HAZARD))as 'SALES'
FROM #sqlbpt
--ROAD HAZARD ADJ
INSERT INTO #TOTALSMAN
SELECT '17' AS 'LINE','ROAD HAZARD ADJ ' as 'CATEGORY',SUM(CONVERT(INTEGER,QTY)) as "QTY",
SUM(CONVERT(MONEY,SALES))+SUM(CONVERT(MONEY,EXCISE))as 'SALES'
FROM #sqlbpd2 WHERE REC_CODE IN ('A','C')
AND REASON IN ('18','19','20')
AND PRODUCT <> '995000800'
--GRAND TOTAL
INSERT INTO #TOTALSMAN
SELECT '18' AS 'LINE',' GRAND-TOTAL',SUM(CONVERT(INTEGER,QTY)),SUM(SALES)
FROM #TOTALSMAN WHERE CONVERT(INTEGER,LINE)>11
SELECT * FROM #TOTALSMAN ORDER BY LINE