Forum Replies Created

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

  • RE: SQL conundrum

    Dan Williams-449672 (11/8/2011)


    any ideas or am i heading down the wrong road?

    You're definitely headed down the wrong road, but without easily consumable sample data and expected results, you're unlikely to...

  • RE: Calculate Current Week and 4 Previous Weeks - Week Starting On Sunday

    You're probably running into problems, because the standard way to do beginning of time period calculations is to use date 0 ('1900-01-01') as the foundation of the calculations. This...

  • 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...

  • 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 =...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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

  • 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...

  • 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...

  • 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...

  • 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

  • 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...

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