Forum Replies Created

Viewing 15 posts - 3,511 through 3,525 (of 4,085 total)

  • RE: Convert table into XML

    The subquery is unnecessary. You can write this as follows:

    SELECT iStudentid as StudentId, OldClassID, NewClassID

    FROM @tblMoveStudentList as StudentMoveSummary

    FOR XML auto,ROOT('ArrayOfStudentMoveSummary'),ELEMENTS

    If you alias the table, it will use that alias...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Special ORDER BY and Grouping

    ColdCoffee (11/3/2011)


    Even better solution

    DECLARE @MaxIDoFMaxPrice INT

    ; WITH RowWithMaxValue AS

    (

    SELECT TOP 1 ID

    FROM @Table

    ORDER BY PRICE DESC

    )

    SELECT @MaxIDoFMaxPrice = ID FROM RowWithMaxValue

    SELECT * FROM @Table

    ORDER BY CASE WHEN ID =...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Calculate First & Last Day of for 2 Months from current date & First & Last Day of the Weeks going back 4 Weeks

    Welsh Corgi (11/2/2011)


    I'm on 2 months back but I don't have the Date Ending down on all but a few, e.x. '2011-11-30 23:59:59.000'

    You are potentially missing some records like '2011-11-30...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Query performance

    GSquared (11/2/2011)


    O.RecID being null doesn't necessarily mean a missing row. Might, but could also just be a nullable columns in the table.

    Not by itself, but the fact that it's...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Query performance

    Sean Lange (11/2/2011)


    I agree with Lynn, we need something to go on here.

    However, just in the skeleton you posted you can increase performance AND accuracy to at least some degree...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Opening and Closing Balance

    getusama-1105611 (11/2/2011)


    I tired that but gave the below error:

    Msg 157, Level 15, State 1, Line 100

    An aggregate may not appear in the set list of an UPDATE statement.

    This is the...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Advice on update

    Since windowed functions (like Row_Number) can't be used directly in an UPDATE statement, you'll need to use a CTE. Otherwise, you have everything that you need to solve this...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Advice on update

    ROW_NUMBER() partitioned by your group will give you the results that you want. If you want tested code, provide the sample data and results that Phil asked for.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: How to add columns dynamically,.,..,.,

    Sean Lange (11/1/2011)


    It just isn't a "here is the code for you" type of solution. You are going to have to read the second article I linked and understand how...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: How to add columns dynamically,.,..,.,

    ramanamreddy (11/1/2011)


    but in my requirement, my code works dynamically that means in my real work I don't know how many records are going to repeat with different phone no.s, I...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: How to add columns dynamically,.,..,.,

    ramanamreddy (11/1/2011)


    I don't need any average or sum, I can use it in the query if I want but not in the output,.,.,

    Even though it doesn't look like it, you...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: RANK / PARTITION BY <range> Possible

    You would just use your CASE expression for your PARTITION BY expression.

    SELECT Rank() Over( PARTITION BY CASE WHEN ... THEN ... END ORDER BY expression )

    FROM YourTable

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Date manipulation and pivottable in excel

    Here is a shot in the dark at a solution.

    ;

    WITH Totals_Ranked AS (

    SELECT *, Row_Number() OVER (PARTITION BY m10_Class_Code ORDER BY Month_Start DESC) AS Month_Rank

    , Row_Number() OVER ( PARTITION BY...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Date manipulation and pivottable in excel

    It wasn't chastisement, it's realism. You have to understand that everyone here is a volunteer. The more hurdles you place in front of people, the fewer will even...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Date manipulation and pivottable in excel

    First, the idea behind including a SAMPLE is that it is large enough to provide a realistic representation of the data, BUT NO LARGER. Since you are grouping on...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 3,511 through 3,525 (of 4,085 total)