Select date period with Vb.net

  • Im try to select some record between two date but i dont understand why my sintax is not correct.

    The comand is:

    "Select count(*) from FILENAME where SUBSTRING(FIELD1,19,4) > 2005 AND TIPCON = '1' and DATA between '2008-03-01' and '2008-03-31'"

    why is not working ???????

    thank you in advance

    Alberto.

  • Check your structure. I created a structure like this:

    CREATE TABLE dbo.FileName

    (

    tipcon INT

    ,data DATETIME

    ,field1 VARCHAR(25)

    )

    And your query ran just fine. No syntax errors. Are you sure you ahve a column called Field1?

    SELECT COUNT(*)

    FROM FILENAME

    WHERE SUBSTRING(FIELD1, 19, 4) > 2005

    AND TIPCON = '1'

    AND DATA BETWEEN '2008-03-01' AND '2008-03-31'

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • The BETWEEN is fine.

    What error message are you getting?

  • now is ok.....

    i forget to put ' on the sql string !!!!

    thank you very much !!!!!!!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply