SQL Server Performance

need little bit help in my query

Discussion in 'General Developer Questions' started by isa, Nov 15, 2006.

  1. isa New Member

    hello everyone :
    here is my query:

    Declare @Date datetime

    select top 1
    (select count(*) as [Re] from Buyers where RegistrationDate= @Date) as '7',
    (select count(*) as [ree] from Buyers where RegistrationDate = DATEADD(DAY, -1, DATEDIFF(DAY, 0, @Date))) as '6',
    (select count(*) from Buyers where RegistrationDate = DATEADD(DAY, -2, DATEDIFF(DAY, 0, @Date))) as '5',
    (select count(*) from Buyers where RegistrationDate = DATEADD(DAY, -3, DATEDIFF(DAY, 0, @Date))) as '4',

    from Buyers

    as if u see i used the alias 7,6,5,4 (hardcoded) now i used here as it gets the actaul day of the week of the date it retrived , for example in sqlserver 2000 we used datepart(dw,@Date) function for getting day of week , iused this as heading of my columns , plz tell me how can i get this ,
    plz tell me abt this.

    isa
  2. FrankKalis Moderator

  3. khtan New Member

    why don't use use a generic column name ?
    like today, yesterday etc ? Wouldn't using dynamic name cause problem to your front end ?


    KH
  4. Madhivanan Moderator

    Read about Cross-tab reports in sql server help file
    Also do google search on Dynamic Cross tab

    Madhivanan

    Failing to plan is Planning to fail

Share This Page