Forum Replies Created

Viewing 15 posts - 946 through 960 (of 1,439 total)

  • RE: how to get only duplicate rows from table

    Here's another way

    WITH cteDupeName AS (

    SELECT RowNum, Name, SomeValue,

    COUNT(*) OVER(PARTITION BY Name) AS cn

    FROM #TestData)

    SELECT RowNum, Name, SomeValue

    FROM cteDupeName

    WHERE cn>1

    ORDER BY RowNum;

  • RE: Stuck on T-sql with ordering of result set

    Lynn Pettis (1/22/2010)


    Perfect, Mark!

    Thanks for the feedback!

  • RE: Stuck on T-sql with ordering of result set

    Try this

    SELECT ...

    FROM ...

    ORDER BY MAX(QNTY) OVER(PARTITION BY PartGroup) DESC, QNTY DESC

  • RE: How to get this?

    I think this gives you what you want, but I don't fully understand the requirements

    SELECT n.Numbers,

    COALESCE(STUFF((SELECT ','+p.Name AS "text()"

    ...

  • RE: SQL Query Help

    You can also replace the multiple 'OR's with an 'IN'

    SELECT STK_STOCK_2.STKCODE2 AS [Stock Code], STK_STOCK_2.STK_SANALYSIS1 AS [Price Line 1], STK_STOCK_2.STK_SANALYSIS2 AS [Price Line 2],

    ...

  • RE: Need help with a correlated query

    WITH CTE AS (

    SELECT [CustNo], [ContractNo], [RNo], [DateFrom], [Discount],

    ROW_NUMBER() OVER(PARTITION BY [CustNo], [ContractNo], [RNo] ORDER BY [DateFrom] DESC) AS rn

    ...

  • RE: SQL XML

    This should do it

    SELECT a.MapID,

    a.SeriesID,

    STUFF((SELECT ','+CAST(b.Year AS VARCHAR(10)) AS "text()"

    ...

  • RE: Convert code from Implicit to Explicit

    Here's another guess

    SELECT JOB.EMPLID,

    JOB.FILE_NBR,

    PER.NAME,

    JOB.PAYGROUP,

    ...

  • RE: Can I do this in one Update Statement?

    Try this

    UPDATE t1

    SET multi_flag='Y'

    FROM MyTable t1

    WHERE EXISTS (SELECT * FROM MyTable t2

    WHERE t2.exe_name=t1.exe_name

    ...

  • RE: Having query

    Untested, you may have issues with NULLs in your data

    select t1.ID, t1.Tel1, t1.Tel2, t1.Tel3, t1.Tel4

    from table1 t1

    where exists (select * from table1 t2

    ...

  • RE: Some general questions

    andy 21711 (1/15/2010)


    2) How can deadlocks appear in a database which doesn't use transactions?

    Triggers can cause this

  • RE: row_number function

    sqlislife (1/14/2010)


    Thanks but I tried the dense_rank and it didn't work for me. Great piece of information learned though.

    Presumably this?

    select ID, name,

    dense_rank() over (order by id asc) as Numbering,

    count(*) over...

  • RE: Select statement question

    Sounds like a homework assignment, can you post what you have tried so far. Also what happens if a customer has two store locations with the same highest charges?

  • RE: How would you write this Query, maby CTE?

    I've had to guess at what is a value 'Father' node, but gives the correct results with your data

    declare @t table(Father int, Item int)

    insert into @t(Father,Item)

    select 49588, 71246 union all

    select...

  • RE: Complicated grouping data

    Untested...

    WITH CTE AS (

    SELECT A,B,C,V,

    ROW_NUMBER() OVER(PARTITION BY A ORDER BY B,C DESC) AS rn

    FROM ViewA)

    SELECT A,C,V

    FROM CTE

    WHERE rn=1

Viewing 15 posts - 946 through 960 (of 1,439 total)