Viewing 15 posts - 841 through 855 (of 1,439 total)
Maybe this?
select sum(mycount)
from (
select count(*) as mycount
from partno_table
group by partno
)x
March 9, 2011 at 8:59 am
Ideally you should provide table definitions for all relevant tables along with sample data in the format
CREATE TABLE dbo.MILEAGE(ZIPCODEFROM VARCHAR(.... )
INSERT INTO dbo.MILEAGE ...
You'll usually get more responses. Meanwhile, here's...
March 3, 2011 at 8:46 am
DerbyNeal (3/3/2011)
Thanks - Firstly, the structure is perfect.
However, the 'Postcode' values aren't being pulled from the Mileage table though. The output contains the values that I gave in...
March 3, 2011 at 7:11 am
See if this helps
DECLARE @MILEAGE TABLE(ZIPCODEFROM VARCHAR(30),ZIPCODETO VARCHAR(30), ID VARCHAR(30), NAME VARCHAR(30), RIGIDACC VARCHAR(30))
INSERT INTO @MILEAGE(ZIPCODEFROM,ZIPCODETO,ID,NAME,RIGIDACC)
SELECT 'XX16 6DN',NULL,'start','Start',1 UNION ALL
SELECT NULL,'ZZ21 2EU','end','End',NULL ;
WITH Unpivotted (ZIPCODEFROM ,ZIPCODETO,Value,Name) AS (
SELECT ZIPCODEFROM...
March 3, 2011 at 6:27 am
SELECT testId,testVersion,
MAX(CASE WHEN AdminType='CAB' THEN StatusId END) AS CAB,
MAX(CASE WHEN AdminType='RM' THEN StatusId END) AS RM,
...
March 2, 2011 at 3:28 am
Try this
CREATE TABLE #Data(ShortDate DATETIME,FlowDirection INT)
INSERT INTO #Data(ShortDate,FlowDirection)
SELECT '20010101', 0 UNION ALL
SELECT '20010102', 1 UNION ALL
SELECT '20010103', 1 UNION ALL
SELECT '20010104', 0 UNION ALL
SELECT '20010105', -1 UNION ALL
SELECT '20010106', 0...
February 18, 2011 at 1:43 pm
Another way
WITH Starts AS (
SELECT a.clientID, a.lastName, a.firstName, a.startDate
FROM #temp a
WHERE NOT EXISTS (SELECT * FROM #temp b
...
January 28, 2011 at 2:38 am
Should be enough to get you started...
WITH Summary AS (
SELECT Username ,
SUM(CASE WHEN PositionTypeCode = 'AMP' THEN 1 ELSE 0 END) AS AMP,
...
January 24, 2011 at 8:15 am
Ninja's_RGR'us (1/21/2011)
CELKO (1/21/2011)
In Standard SQL there is an...
January 22, 2011 at 2:38 am
dibbydibby (1/18/2011)
January 18, 2011 at 3:45 am
Try UNION ALL instead of UNION
January 18, 2011 at 3:42 am
SELECT CONVERT(CHAR(10),s.Date,120) AS Date,
CONVERT(CHAR(5),s.Time,108) AS StarTime,
CONVERT(CHAR(5),e.Time,108) AS EndTime,
s.CardNumber,
...
January 17, 2011 at 3:21 am
Changing
value('.','varchar(max)'),1,1,'')
to
value('(./text())[1]','varchar(max)'),1,1,'')
appears to give a better query plan
Great article BTW.
January 12, 2011 at 7:16 am
Adi Cohn-120898 (1/10/2011)
January 10, 2011 at 6:19 am
Try this. You could also use the 'quirky update' method from here
http://www.sqlservercentral.com/articles/T-SQL/68467/
which would be very fast.
WITH CTE1 AS (
SELECT tradeId,
tradeClosedDateTime,
...
January 6, 2011 at 7:49 am
Viewing 15 posts - 841 through 855 (of 1,439 total)