Loading ...
Sorry, an error occurred while loading the content.
 

Sql help needed

Expand Messages
  • O S
    Hello I like to know how to get the week of the month. I have a table like logID, signinDate, personId select Count(logId) FROm myLogTable WHERE signinDate
    Message 1 of 12 , Apr 4, 2008
      Hello

      I like to know how to get the week of the month. I have a table like

      logID, signinDate, personId

      select Count(logId) FROm myLogTable WHERE signinDate between ? AND ?
      GROUP BY year(signinDate), month(signinDate), week(signinDate)
      ORDER BY year(signinDate), month(signinDate), week(signinDate)

      Above sql doesnt work for me

      I am trying to show it like

      Year 2008
      Month 3
      Week 1
      PersonID1 = 3 << where 3 is the count of logID
      PersonID2 = 44
      Week 2 PersonID 1 = 2

      etc

      please help.. thanks








      _________________________________________________________________
      Get Hotmail on your mobile. Text MSN to 63463 now!
      http://mobile.uk.msn.com/pc/mail.aspx

      [Non-text portions of this message have been removed]
    • John Warner
      DBMS? Also could you tell us just a tiny bit about the tables and columns in the database? John Warner
      Message 2 of 12 , Apr 4, 2008
        DBMS? Also could you tell us just a tiny bit about the tables and columns
        in the database?

        John Warner




        > -----Original Message-----
        > From: SQLQueriesNoCode@yahoogroups.com
        > [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of O S
        > Sent: Friday, April 04, 2008 8:08 AM
        > To: sqlqueriesnocode@yahoogroups.com
        > Subject: [SQLQueriesNoCode] Sql help needed
        >
        >
        >
        >
        > Hello
        >
        > I like to know how to get the week of the month. I have a table like
        >
        > logID, signinDate, personId
        >
        > select Count(logId) FROm myLogTable WHERE signinDate between
        > ? AND ? GROUP BY year(signinDate), month(signinDate),
        > week(signinDate) ORDER BY year(signinDate),
        > month(signinDate), week(signinDate)
        >
        > Above sql doesnt work for me
        >
        > I am trying to show it like
        >
        > Year 2008
        > Month 3
        > Week 1
        > PersonID1 = 3 << where 3 is the count of logID
        > PersonID2 = 44
        > Week 2 PersonID 1 = 2
        >
        > etc
        >
        > please help.. thanks
        >
        >
        >
        >
        >
        >
        >
        >
        > _________________________________________________________________
        > Get Hotmail on your mobile. Text MSN to 63463 now!
        > http://mobile.uk.msn.com/pc/mail.aspx
        >
        > [Non-text portions of this message have been removed]
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
      • O S
        DBMS: sql server table: mylogtable( logID int , signinDate date, personId int ) To: SQLQueriesNoCode@yahoogroups.comFrom: john@jwarner.comDate: Fri, 4 Apr
        Message 3 of 12 , Apr 4, 2008
          DBMS: sql server
          table: mylogtable( logID int , signinDate date, personId int )


          To: SQLQueriesNoCode@yahoogroups.comFrom: john@...: Fri, 4 Apr 2008 08:40:14 -0400Subject: RE: [SQLQueriesNoCode] Sql help needed




          DBMS? Also could you tell us just a tiny bit about the tables and columnsin the database?John Warner> -----Original Message-----> From: SQLQueriesNoCode@yahoogroups.com > [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of O S> Sent: Friday, April 04, 2008 8:08 AM> To: sqlqueriesnocode@yahoogroups.com> Subject: [SQLQueriesNoCode] Sql help needed> > > > > Hello> > I like to know how to get the week of the month. I have a table like > > logID, signinDate, personId> > select Count(logId) FROm myLogTable WHERE signinDate between > ? AND ? GROUP BY year(signinDate), month(signinDate), > week(signinDate) ORDER BY year(signinDate), > month(signinDate), week(signinDate)> > Above sql doesnt work for me > > I am trying to show it like> > Year 2008> Month 3> Week 1> PersonID1 = 3 << where 3 is the count of logID > PersonID2 = 44> Week 2 PersonID 1 = 2> > etc> > please help.. thanks> > > > > > > > > __________________________________________________________> Get Hotmail on your mobile. Text MSN to 63463 now! > http://mobile.uk.msn.com/pc/mail.aspx> > [Non-text portions of this message have been removed]> > > ------------------------------------> > Yahoo! Groups Links> > >






          _________________________________________________________________
          Welcome to the next generation of Windows Live
          http://www.windowslive.co.uk/get-live

          [Non-text portions of this message have been removed]
        • John Warner
          Didn t read your question close enough, try this in QA DECLARE @date datetime SET @date = 20080404 SELECT DATEPART(week, @date) - DATEPART(week,
          Message 4 of 12 , Apr 4, 2008
            Didn't read your question close enough, try this in QA

            DECLARE @date datetime
            SET @date = '20080404'

            SELECT
            DATEPART(week, @date) - DATEPART(week, DATEADD(month, DATEDIFF(month, 0,
            @date), 0)) +1

            Watch line wrapping on the last line, it ends with "+1"

            John Warner




            > -----Original Message-----
            > From: SQLQueriesNoCode@yahoogroups.com
            > [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of O S
            > Sent: Friday, April 04, 2008 8:54 AM
            > To: sqlqueriesnocode@yahoogroups.com
            > Subject: RE: [SQLQueriesNoCode] Sql help needed
            >
            >
            >
            > DBMS: sql server
            > table: mylogtable( logID int , signinDate date, personId int )
            >
            >
            > To: SQLQueriesNoCode@yahoogroups.comFrom:
            > john@...: Fri, 4 Apr 2008 08:40:14 -0400Subject:
            > RE: [SQLQueriesNoCode] Sql help needed
            >
            >
            >
            >
            > DBMS? Also could you tell us just a tiny bit about the tables
            > and columnsin the database?John Warner> -----Original
            > Message-----> From: SQLQueriesNoCode@yahoogroups.com >
            > [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of O S>
            > Sent: Friday, April 04, 2008 8:08 AM> To:
            > sqlqueriesnocode@yahoogroups.com> Subject: [SQLQueriesNoCode]
            > Sql help needed> > > > > Hello> > I like to know how to get
            > the week of the month. I have a table like > > logID,
            > signinDate, personId> > select Count(logId) FROm myLogTable
            > WHERE signinDate between > ? AND ? GROUP BY year(signinDate),
            > month(signinDate), > week(signinDate) ORDER BY
            > year(signinDate), > month(signinDate), week(signinDate)> >
            > Above sql doesnt work for me > > I am trying to show it like>
            > > Year 2008> Month 3> Week 1> PersonID1 = 3 << where 3 is the
            > count of logID > PersonID2 = 44> Week 2 PersonID 1 = 2> >
            > etc> > please help.. thanks> > > > > > > > >
            > __________________________________________________________>
            > Get Hotmail on your mobile. Text MSN to 63463 now! >
            > http://mobile.uk.msn.com/pc/mail.aspx> > [Non-text portions
            > of this message have been removed]> > >
            > ------------------------------------> > Yahoo! Groups Links> > >
            >
            >
            >
            >
            >
            >
            > _________________________________________________________________
            > Welcome to the next generation of Windows Live
            > http://www.windowslive.co.uk/get-live
            >
            > [Non-text portions of this message have been removed]
            >
            >
            > ------------------------------------
            >
            > Yahoo! Groups Links
            >
            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.