Results 1 to 3 of 3

Thread: [RESOLVED] help with SQL and dates and update

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    111

    Resolved [RESOLVED] help with SQL and dates and update

    1.How can you select the fields with an SQL statement and using a date column. For example:
    VB Code:
    1. .RecordSource = "Select * from tableA where Adate between " & txtDate1 & " and " & txtDate 2

    2.Can I get somehow the records that i need and perform calculations with them and save the calculation result in another column in the same records?

    for example, with a loop add number1 and number2 to result which all are columns in my database? I can send the code if you prefer...
    in a for loop:
    (.Fields(10)) = (.Fields(2))+(.Fields(3))
    how do I update (.Fields(10))??

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help with SQL and dates and update

    That depends on what database you are using.

    Access wants # arounds dates and SQL Server wants single quotes.

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: help with SQL and dates and update

    Quote Originally Posted by rasty1611
    1.How can you select the fields with an SQL statement and using a date column. For example:
    VB Code:
    1. .RecordSource = "Select * from tableA where Adate between " & txtDate1 & " and " & txtDate 2
    Code:
    .RecordSource = "Select * from tableA where Adate between #" & txtDate1 & "# and #" & txtDate 2 & "#"
    also don't know if it's a type, but txtDate 2 should be txtDate2 - no space.
    2.Can I get somehow the records that i need and perform calculations with them and save the calculation result in another column in the same records?

    for example, with a loop add number1 and number2 to result which all are columns in my database? I can send the code if you prefer...
    in a for loop:
    (.Fields(10)) = (.Fields(2))+(.Fields(3))
    how do I update (.Fields(10))??
    That would be an UPDATE statement in SQL.
    I wouldn't do it your intended way, maybe a matter of preference. I'd calculate Field2 + Field3, then Update field 10, using SQL. It's (almost) always faster, and easier to trace errors. IMHO. I
    Tengo mas preguntas que contestas

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