Forum Replies Created

Viewing 15 posts - 616 through 630 (of 1,439 total)

  • RE: Vertical to Horizontal

    Try this

    DECLARE @DetailTable TABLE(Store INT, PhoneNr VARCHAR(30))

    INSERT INTO @DetailTable(Store, PhoneNr)

    SELECT 4711, '49911-1111111' UNION ALL

    SELECT 4711, '49911-1111112' UNION ALL

    SELECT 4711, '49911-1111113';

    WITH CTE AS (

    SELECT Store, PhoneNr,

    ...

  • RE: Grouping based on contiguous dates

    Jeff Moden (3/27/2012)


    Eugene Elutin (3/27/2012)


    ...

    Try adding this into the original sample data

    SELECT 'Jun 1 2011 12:00AM','1','10','20' UNION ALL

    The results of the two queries are different.

    My query will only ...

  • RE: Grouping based on contiguous dates

    Eugene Elutin (3/27/2012)


    I still couldn't get it from your explanation, but looks like I do see now what you want ...

    Lets create some more test data (around 1.3 millions records)

    declare...

  • RE: Grouping based on contiguous dates

    philippe-546556 (3/27/2012)


    Brilliant. I don't understand it yet, but still brilliant. Many thanks for your help!

    Philippe

    The "Group Islands of Contiguous Dates" article I referenced explains how this works.

  • RE: Grouping based on contiguous dates

    See the link here

    http://www.sqlservercentral.com/articles/T-SQL/71550/

    WITH CTE AS (

    SELECT [Month],[ItemID],[count A],[count B],

    ROW_NUMBER() OVER(PARTITION BY [ItemID] ORDER BY [Month]) -

    ...

  • RE: Problem with XML content into SQL

    Use OUTER APPLY

    SELECT x.name.value('@name[1]', 'VARCHAR(10)') AS name

    ,y.name.value('@ID[1]', 'INT') as ID

    ,y.name.value('@color[1]', 'VARCHAR(10)') as Color1

    ,z.name.value('@color[1]', 'VARCHAR(10)') as Color2

    FROM @data.nodes('/Automobile/Car') x(name)

    OUTER APPLY x.name.nodes('Properties') y(name)

    OUTER APPLY x.name.nodes('PropertiesGroup') z(name)

  • RE: Primary Key: GUID vs. INT

    GilaMonster (3/26/2012)


    Nothing wrong with a guid primary key. What causes performance problems is a Guid column used as the clustered index key. So if you're going to have Guid primary...

  • RE: Returning Lowest Value From Table

    Just a GROUP BY should do it

    SELECT [Model Number], MIN(Price) AS Price

    FROM myTable

    GROUP BY [Model Number]

  • RE: Display all the users with group descriptions for semicolon seperated values.

    SELECT u.C8,

    (SELECT g.groupname+';' AS "text()"

    FROM group_cache g

    WHERE...

  • RE: Sum Overlapping DateTime Ranges

    This gives you just the active and idle time in minutes. You'll have to format this to give HH:MM:SS.

    WITH AllTimes AS (

    SELECT MachineID, TimeStart AS tm

    FROM @TempSource

    UNION

    ...

  • RE: Transpose Row into columns

    See if this helps

    DECLARE @phoneDetail TABLE(CustomerID INT,Row INT,PhoneType VARCHAR(20),

    ...

  • RE: How to convert this XML into columns

    Still not clear what you're asking. If your XML is in a table, you can use CROSS APPLY to get the values.

    SELECT x.r.value('@date_changed','DATETIME') AS date_changed,

    ...

  • RE: How to convert this XML into columns

    This will give the XML as columns. You'll need to give more information about how to calculate the other columns you're after.

    DECLARE @x XML

    SET @x='<Rates>

    <Rate date_changed="Nov 10 2011...

  • RE: discusssion forum,thread,messages,totalnumber of replies last post date

    Using recursive CTEs

    WITH Recur AS (

    SELECT MessageThread,MessageContent,MessageID,MessageDate

    FROM ThreadMessage

    WHERE MessageParent=0

    UNION ALL

    SELECT r.MessageThread,r.MessageContent,m.MessageID,m.MessageDate

    FROM ThreadMessage m

    INNER JOIN Recur r ON r.MessageID=m.MessageParent

    )

    SELECT MessageThread AS ThreadID,

    ...

  • RE: Sum a column for a set of Trees on a Recursive Table

    You can use recursive CTEs for this

    SET NOCOUNT ON

    DECLARE @fctTable TABLE(Id INT,refTableId INT)

    INSERT INTO @fctTable(Id,refTableId)

    SELECT 1 , 2 UNION ALL

    SELECT 2 , 7 UNION ALL

    SELECT 3 , 4 UNION ALL

    SELECT...

Viewing 15 posts - 616 through 630 (of 1,439 total)