CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Sql

  1. #1
    Join Date
    Feb 2001
    Location
    New Jersey
    Posts
    312

    Sql

    I am having a problem with my SQL statement...

    Code:
    stry = "Select * from TabCheckHistory where ClientId = '" & CID & "'"
    stry = stry & " and Format(CheckDate,'YYYY') = " & LastYear
    
    I guess I can't use the format function in SQL????
    http://www.dewgames.com
    Shareware and Free games!

  2. #2
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Currently your sql statement reads like this:

    stry = "Select * from TabCheckHistory where ClientId = '12345' and 2003 = 2003

    I think what you want is

    stry = "Select * from TabCheckHistory where ClientId = '" & CID & "'"
    stry = stry & " and DatePart('yyyy', checkdate) = '" & LastYear & "'"
    Be nice to Harley riders...

  3. #3
    Join Date
    Apr 2002
    Location
    Sri Lanka
    Posts
    71

    Smile DatePart function returns int...

    Hi,

    DatePart function returns 'int' as its' output type. So the above posting should change like this...

    stry = "Select * from TabCheckHistory where ClientId = '" & CID & "'"
    stry = stry & " and DatePart('yyyy', checkdate) =" & LastYear

    Also note that this SQL statement can only be used with SQL Server and Access.
    __________________
    - Buddhi from Sri Lanka -
    - Paradise of Sinhalese/Buddhists -

  4. #4
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Very true - I added the single quotes in because sql server (and access) will do an implicit conversion (yes...I can be a bad programmer from time to time...) and this way you wouldn't have to cast the text of your input box.

    Buddhi's way is clearly more correct...and I'm lazy
    Be nice to Harley riders...

  5. #5
    Join Date
    Apr 2002
    Location
    Sri Lanka
    Posts
    71

    Smile You are welcome...

    Thanks two dogs....

    Anyway to improve my post you have given me the basis..
    __________________
    - Buddhi from Sri Lanka -
    - Paradise of Sinhalese/Buddhists -

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

Featured