Conversion failed when converting datetime from character string

  • When i previewing the reportgetting below error:

    "Conversion failed when converting datetime from character string"

    The query in the dataset1:

    Select f1,f2,f3

    from tablename

    where date=@Year and date=@Monthname

    dataset2:

    select datepart(yyyy,date) from table

    dataset3:

    select datename(month,date) from table where datepart(yyyy,date)=@year

    Thanks in advance

  • My first question is how can you have a single value equal to 2 different values?

    where date=@Year and date=@Monthname

  • srichaitya (6/15/2011)


    When i previewing the reportgetting below error:

    "Conversion failed when converting datetime from character string"

    The query in the dataset1:

    Select f1,f2,f3

    from tablename

    where date=@Year and date=@Monthname

    dataset2:

    select datepart(yyyy,date) from table

    dataset3:

    select datename(month,date) from table where datepart(yyyy,date)=@year

    Thanks in advance

    Maybe try something like

    Select f1,f2,f3

    from tablename

    where Year(date)=@Year and month(date)=@Monthname

    what datatype is 'date' and what are @Year and @Monthname declared as?

  • Year can be integer and Month name can be varchar(20) , Please use DATEPART function while extracting out the specific Month/Year/Day out of it,

    Make sure mangoes must be compared with mangoes...

    Let me know if you need further claerifications.

  • I guess you are using Visual Studio to write the queries (dataset1 ...),

    you can try SQL Server Management Studio here you can edit your queries easier and then paste them into Visual Studio (at least this is what I am doing).

    If Month is a character (i.e. May, June) then you can use DateName funtion.

    In which case the where clause can be as bellow:

    DATEPART(yyyy,date) = @Year

    AND DATENAME( MONTH, GETDATE() ) = @Monthname

    Regards,

    Iulian

  • Thanks for all. .

    I wrote the query like below.it works well

    Select f1,f2,f3

    from table

    where depart(yyyy,date)=@year and datename(m,date)=@monthname

Viewing 6 posts - 1 through 5 (of 5 total)

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