Viewing 15 posts - 166 through 180 (of 1,438 total)
Luis Cazares (5/25/2015)
WITH CTE AS(
SELECT *, (ROW_NUMBER() OVER(PARTITION BY Country ORDER BY Id)+ 2) / 3 AS rowrank
...
May 25, 2015 at 11:48 am
Not totally sure what you're after but this may work
SELECT *,
DATEDIFF(Day,MIN(OrderDate) OVER(PARTITION BY CustomerID),OrderDate) + 1
FROM OrderRanking
ORDER BY OrderID
May 24, 2015 at 9:15 am
This should work for you
WITH CTE AS (
SELECT *,ROW_NUMBER() OVER(PARTITION BY Account_ID ORDER BY Priority) AS rn
FROM staging_account)
DELETE FROM CTE
WHERE rn > 1;
May 20, 2015 at 6:27 am
Maybe this?
declare @xmldoc as xml= '<Text>This is firstline<Break></Break>This is second line<Break></Break>This is third line</Text>';
declare @break char(1) = char(10);
select @xmldoc.query('for $c in /Text/text() return concat($c,sql:variable("@break"))').value('.','varchar(max)');
May 6, 2015 at 6:43 am
Sigerson (5/5/2015)
@Mark Cowne+10
Very elegant solution.
Thanks!
May 5, 2015 at 1:41 pm
This works with your data
WITH CTE AS (
SELECT Hwy, Start, [End], Condition1, Condition2,
ROW_NUMBER() OVER(PARTITION BY Hwy ORDER BY Start, [End]) -
...
May 2, 2015 at 9:01 am
WITH CTE AS (
SELECT ItemID, [Version],
ROW_NUMBER() OVER(PARTITION BY ItemID ORDER BY CAST(PARSENAME([Version],3) AS INT) DESC,CAST(PARSENAME([Version],2) AS INT) DESC,CAST(PARSENAME([Version],1) AS INT) DESC) AS rn
FROM...
May 1, 2015 at 7:57 am
Change
N'<th>Db_denydatareader</th></tr>' +
to
N'<th>Db_denydatareader</th>' +
April 29, 2015 at 4:15 am
A change to the end of Lynns query gives you the concatenated results you're after
with basedata as (
select
[sid],
scode,
cast(stuff(scode,1,0,replicate(N'...
April 29, 2015 at 2:25 am
Something like this?
SELECT a.Account, a.[Acct Ref], a.[Txn Set], a.[Txn Ref],
CASE WHEN COUNT(*) = 1 THEN MAX(b.[Account]) ELSE '1 to Many' END AS [Alt...
April 28, 2015 at 7:34 am
Assuming weeknumber is contiguous you can do this
SELECT a.WeekNr,a.Data
FROM mytable a
WHERE EXISTS(SELECT * FROM mytable b
WHERE b.WeekNr...
April 22, 2015 at 9:36 am
You're on the right lines with ROW_NUMBER
WITH CTE AS (
SELECT ID ,Total_Used , Date_,
ROW_NUMBER() OVER(PARTITION BY YEAR(Date_),MONTH(Date_) ORDER BY Date_ DESC,Total_Used DESC) AS...
April 22, 2015 at 8:23 am
Here's a solution using recursion, don't expect it to be quick though.
WITH Ordered AS (
SELECT m.MACHINE_NUMBER,m.VALUE,m.EVENT_DATE,
ROW_NUMBER() OVER(PARTITION BY m.MACHINE_NUMBER ORDER BY m.EVENT_DATE) AS...
April 21, 2015 at 6:07 am
Here's a different approach
WITH RemovedY AS (
SELECT t.ID,
t.CODE,
SUBSTRING(t.CODE,(s.number*5)+1,4) AS CODE2,
...
April 20, 2015 at 3:10 am
Viewing 15 posts - 166 through 180 (of 1,438 total)