Forum Replies Created

Viewing 15 posts - 16 through 30 (of 309 total)

  • RE: Query Performance

    thava (8/15/2013)


    SELECT c.CLIName1, c.CLICode, g.AGPName1 AS [GL Account Group], a.COAName1 AS [GL Account], d.DIVName1,

    a.COACode2Code AS [GLChart Code 2], a.COACode2Name1 AS [GLChart Code...

  • RE: Is overpunch amenable to cross apply?

    ChrisM@Work (8/13/2013)


    On my machine, your code is three times faster - but the negative numbers are different to mine and to Dwain's.

    I think my handling of negative numbers is correct....

  • RE: How to Group by the Past Seven Days

    You could use something like this:

    GROUP BY datediff(day, StartTime, getdate())/7

  • RE: Is overpunch amenable to cross apply?

    ChrisM@Work (8/13/2013)


    It's two orders of magnitude out though, Stefan 😉

    OK, So, the corrected code with conversion to money and divide by 100 looks like this:

    alter function fixop2(@a varchar(20)) returns table

    as

    return...

  • RE: Is overpunch amenable to cross apply?

    If you want maximum performance you could use something like this:

    create function fixop2(@a varchar(20)) returns table

    as

    return select

    case

    when right(@a,1) between 'A' and 'I' then +cast(left(@a, len(@a)-1) as int)*10 + (ascii(right(@a,1)) -...

  • RE: How to update Flag based on Maximum Amount

    Create Table #Temp

    (

    Lnno Varchar(15),

    Custcode varchar(10),

    Flag varchar(10),

    Amount Int,

    Amount_Flag varchar(1)

    )

    Insert Into #Temp

    Values ('1','A1','Cust',1000,''),

    ('1','A1','Cust',1000,'')

    Select * from #Temp

    ;with cte as (

    Select row_number() over (partition by Lnno order by amount desc, flag desc, custcode) as...

  • RE: How to update Flag based on Maximum Amount

    avdhut.k (8/12/2013)


    Hi,

    I mean Now rest of the things are correct in my requirement,

    Now, In case where for two records, if flag...

  • RE: Query help - summing between dates ranges and calculations...

    Easy enough to change the WHERE on the date to an OR with the two specific date ranges.

    If the @StartDate is the start of the current period -- which seemed...

  • RE: Query help - summing between dates ranges and calculations...

    I delayed the lookup of CustomerName to avoid having to GROUP on it -- GROUP BY is an especially expensive operation on varchar columns.

    OK, I suppose this could be a...

  • RE: Query Help - Sum by Month

    Nice!

    My solution looks like this:

    ;with cte1 as (

    -- get all interesting months

    select dateadd(month, N, '20100101') FirstDay

    from tsqlc_Tally

    where N < 120

    )

    select RIGHT(CONVERT(char(10), FirstDay, 103), 7), SumAmount

    from cte1

    cross apply (

    select sum(Amount)...

  • RE: How to update Flag based on Maximum Amount

    ('3','C1','Cust',0,''),

    ('3','C2','CoAp',1000,''),

    ('3','C3','CoAp',1000,''),

    ('3','C4','CoAp',5000,'')

    I has to Update Amount_Flag as Y,to maximum Amount for that Lnno.

    3)In Case Lnno = 3,Cust has amount 0,but two CoAp has Amount same that is...

  • RE: How to update Flag based on Maximum Amount

    Would this work for you:

    ;with cte as (

    Select row_number() over (partition by Lnno order by amount desc, flag desc, custcode) as rn,*

    from #Temp

    )

    update cte

    set Amount_Flag = 'Y'

    where rn=1

  • RE: Query help - summing between dates ranges and calculations...

    This should work.

    Note that the code is untested since you did not provide actual table definitions and test data, but the principle should work.

    ;with

    thisYear as (

    -- Get summarized values...

  • RE: Help with the query and index.

    Solutions I tried:

    1) Add a computed column with definition: (case when EndDateTime is not null then EndDateTime Else StartDateTime End) and have an index on this. This works perfect but...

  • RE: Query Help - Sum by Month

    A little challenge:

    Assume there is a clustered index on the date column.

    Can you create a query that exploits the clustered index to achieve even better performance?

Viewing 15 posts - 16 through 30 (of 309 total)