Why does this crash SQL7 ?
From: Lisa Pearlson (no_at_spam.plz)
Date: 08/13/04
- Next message: Dan Guzman: "Re: EXISTS -- NOT EXISTS QUERY"
- Previous message: weeee: "Remote dedicated MS SQL connection problem"
- Next in thread: Gert-Jan Strik: "Re: Why does this crash SQL7 ?"
- Reply: Gert-Jan Strik: "Re: Why does this crash SQL7 ?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 13 Aug 2004 02:09:31 +0200
I got the latest SP (4) and MDAC, still this causes a crash..
Anyone know why, and how to circumvent this bug?
CREATE TABLE #test (
[year] smallint,
[month] tinyint,
[product] varchar(100),
[value] money
)
GO
INSERT INTO #test VALUES (2000, 2, 'p-01', 1.00)
INSERT INTO #test VALUES (2000, 2, 'p-02', 2.00)
INSERT INTO #test VALUES (2001, 2, 'p-01', 1.00)
INSERT INTO #test VALUES (2001, 2, 'p-03', 3.00)
INSERT INTO #test VALUES (2002, 2, 'p-01', 1.00)
INSERT INTO #test VALUES (2002, 2, 'p-01', 1.00)
GO
SELECT
a.year,
a.product,
a.month,
ISNULL(o.value, 0) value,
ISNULL((SELECT SUM(value) FROM #test
WHERE year=a.year AND product=a.product AND month<=a.month), 0)
cumul_artikel,
ISNULL((SELECT SUM(value) FROM #test
WHERE year=a.year AND month=a.month), 0) value_month,
ISNULL((SELECT SUM(value) FROM #test
WHERE year=a.year AND month<=a.month), 0) cumul_month
FROM (SELECT
j.year,
j.product,
m.month
FROM
(SELECT DISTINCT [year], [product] FROM #test) j,
(SELECT 1 AS [month]
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5
UNION ALL SELECT 6
UNION ALL SELECT 7
UNION ALL SELECT 8
UNION ALL SELECT 9
UNION ALL SELECT 10
UNION ALL SELECT 11
UNION ALL SELECT 12) m) AS a
LEFT OUTER JOIN #test o
ON o.year = a.year AND o.month=a.month AND o.product=a.product
GO
DROP TABLE #test
GO
Lisa
- Next message: Dan Guzman: "Re: EXISTS -- NOT EXISTS QUERY"
- Previous message: weeee: "Remote dedicated MS SQL connection problem"
- Next in thread: Gert-Jan Strik: "Re: Why does this crash SQL7 ?"
- Reply: Gert-Jan Strik: "Re: Why does this crash SQL7 ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|