Results 1 to 6 of 6

Thread: SQL agian

  1. #1

    Thread Starter
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    Arrow

    I'm trying to retrive all the info in a table that falls in the current month

    this is what I tried

    SELECT ClientData.Address, ClientData.Name, ClientData.LastWork, ClientData.NextScheduled, ClientData.CustomerType, ClientData.JobStatus
    FROM ClientData
    WHERE (((ClientData.NextScheduled) Like (ClientData.NextScheduled)=Date()))
    ORDER BY ClientData.Address;

    it doesn't work
    I don't think I'm using =Date() the right way
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

  2. #2
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Hi,
    if you are using access you can set the month to a number and use the datepart function:

    example:

    SELECT *
    FROM repl_test1 where
    datepart("m", [date_start]) = 3

    This selects everything for marcch of any year. This can be used in combination with "yyyy" - year etc to narrow your search criteria.

    HTH.

    Lenin

  3. #3

    Thread Starter
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    Arrow I'm using vb

    I'm doing it in vb and I've tried using access it doesn't help any even when I use it to generate the SQL

    this is what I'm trying now

    SELECT * FROM database WHERE database.datefield LIKE
    "DATEPART('MONTH','GETDATE()");

    this also does not work sombody please help me out here

    project http://evodev.com/ClientDbase.zip
    Database http://evodev.com/ClientBase.zip
    an ocx the project needs http://evodev.com/floatbutton.zip

    I really need the help getting this report to generate it is the important part the project the whole reson I was commetioned to do it

    thankx to anybody who even downloads and looks at the stuff
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

  4. #4
    Guest

    Wink

    Code:
    Dim dTemp As Date
    dTemp = Month(Now)
    
    oRS.Open "SELECT Address, Name, LastWork, NextScheduled, CustomerType, JobStatus 
    FROM ClientData 
    WHERE NextScheduled=#" & dTemp & "# ORDER BY Address;", oConn
    I'm not much of a guru when it comes to databases, but I think that's about right. oConn is the connection object you're using, oRS is the recordset. I'm not sure about the hashes around the date, but I'm pretty sure I read somewhere that you had to do that (like quotes around a string - it's sequel thing! )

    (Tell me if it works and I'll be well chuffed! )

    [Edited by matthewralston on 05-31-2000 at 06:44 AM]

  5. #5
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    ZanM

    Don't know if this will help


    Code:
    'Find out the current Month Number and Yrea Number 
    'set iMonth and iYear to those values 
    'to equal that number
    Dim iMonth as Integer
    Dim iYear as Integer
    
    SELECT * FROM ClientData 
    WHERE (((DatePart("m",[dateField])=" & iMonth & ") And (DatePart("yyyy",[OriginalDate])=" & iYear & ")));
    ORDER BY ClientData.Address;
    Hope this works

    Gazza

  6. #6

    Thread Starter
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    Arrow I figured it out

    The problem was that I was comparing part of the Date(month) to all of my date field. I just had to get the month from the field and now it works. And of corse then I did the same for the year so it will be from only this may not all the mays from 80 - 2099.

    Thankx everybody.
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width