Viewing 15 posts - 856 through 870 (of 1,491 total)
Or maybe:
;WITH cte
AS
(
SELECT *
,ROW_NUMBER() OVER (PARTITION BY custID, module ORDER BY visit_date DESC) AS RowNum
FROM @t
)
SELECT T.*
FROM @t T
JOIN
(
SELECT C.*
FROM cte C
JOIN
(
SELECT custID, module
,MIN(found_count) AS found_count
,MIN(quality) AS quality
,MIN(pressure) AS pressure
FROM...
May 11, 2010 at 4:22 am
Try something like:
;WITH cte
AS
(
SELECT *
,ROW_NUMBER() OVER (PARTITION BY custID, module ORDER BY visit_date DESC) AS RowNum
FROM @t
)
SELECT C.*
FROM cte C
JOIN
(
SELECT custID, module
,MIN(found_count) AS found_count
,MIN(quality) AS quality
,MIN(pressure) AS pressure
FROM cte
WHERE RowNum...
May 11, 2010 at 4:17 am
To drive by withdrawals with the same idea, try the following:
;WITH Reenrollments
AS
(
SELECT *
...
May 7, 2010 at 9:25 am
Thus all withdrawals will have enrollments following it.
In my query they do.
The idea is that RowNum % 2 = 1 for enrollments and RowNum % 2 = 0 for withdrawals.
May 7, 2010 at 9:12 am
Assuming an enrollment is never followed by an enrollment, I would be inclined to ignore the EndDate.
Try something like:
;WITH Reenrollments
AS
(
SELECT *
,ROW_NUMBER() OVER (PARTITION BY StudentID ORDER BY StartDate) As RowNum
FROM...
May 7, 2010 at 3:17 am
The main clauses in SQL are logically executed in the following order:
FROM (including JOINS)
WHERE
GROUP BY
HAVING
SELECT
DISTINCT
ORDER BY
TOP
April 27, 2010 at 3:10 am
-- *** Test Data ***
DECLARE @t TABLE
(
minutes varchar(3) NOT NULL
)
INSERT INTO @t
SELECT '10'
UNION ALL SELECT '20'
UNION ALL SELECT '60'
-- *** End Test Data ***
SELECT REPLACE(STR(minutes/60, 2), ' ', '0')
+ ':'
+...
April 23, 2010 at 3:30 am
INSERT INTO DATABASE..STAG_TEMP_TABLE
SELECT ABC,SUM(ZXC)ZXC,SUM(XYZ)XYZ
FROM
(
-- Filter data here as the result will be passed up.
-- These two selects may also run in parallel.
SELECT *
FROM DATABASENAME..WWW
WHERE A1 BETWEEN '20091009' AND '20100408'
AND...
April 23, 2010 at 3:03 am
Try putting the 'AND c.AcctName is NULL' into the ON clause of the join to table3.
Also:
a.FllwUpDate < DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0)
will be more efficient than:
a.FllwUpDate < Convert(DateTime,convert(varchar(12),getdate(),101))
April 21, 2010 at 7:30 am
The problem with either renaming the tables or using ALTER VIEW is likely to be obtaining the schema lock.
To avoid this, you should update the main table from the staging...
April 20, 2010 at 9:51 am
As this query is quite straightforward to translate, prove that these two statements produce different results.
select Count(*)
from dbo.it_1_Revenue__Costs rev,dbo.it_2_elist e,dbo.it_2_LOB l,
dbo.it_2_RegionCurrency rg,dbo.it_4_Months_QTRS mnt,dbo.et_Summary_Income_Statement inc
where rev.itemiid*=inc.dimension_1_revenu
and l.itemiid*=inc.dimension_2_lob
and e.itemiid*=inc.elist
and rg.itemiid*=inc.dimension_2_region
and mnt.itemiid*=inc.dimension_4_months
SELECT COUNT(*)
FROM...
April 19, 2010 at 4:17 am
This should work, the trick is to follow the WHERE clause:
SELECT COUNT(*)
FROM dbo.et_Summary_Income_Statement inc
RIGHT JOIN dbo.it_1_Revenue__Costs rev
ON rev.itemiid = inc.dimension_1_revenu
RIGHT JOIN dbo.it_2_LOB l
ON l.itemiid = inc.dimension_2_lob
RIGHT JOIN dbo.it_2_elist e
ON e.itemiid...
April 16, 2010 at 6:53 am
Try something like:
SET ANSI_NULLS, QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER NewAgentRegistration
ON dbo.Client_Agent
AFTER INSERT
AS
SET NOCOUNT ON;
BEGIN TRY
INSERT INTO dbo.Asset(_RGuid, AsNumber, ASName, ASRDate, ASEDate)
SELECT _RGuid
,''
,''
,'' -- Should this be a date???
,'' -- Should this be...
April 8, 2010 at 9:21 am
You have two problems:
1. Your trigger will not cope if multiple rows are inserted.
2. You have a multi-statement trigger with no error handling.
Also, ASNumber is just a formated copy of...
April 7, 2010 at 5:19 am
Viewing 15 posts - 856 through 870 (of 1,491 total)