You must Sign In to post a response.
  • Category: SQL Server

    How to convert var char value into date time format

    i have inserting var-char value like '3-2017' into column name (Test) . means month and year now i want to search records between '3-2017' to '5-2017' please help me how to fetch those records

    select *
    from Testable
    where Test > ='3-2017'
    and Test <='5-2017'

    i have tried above query but i'm not getting proper results

    Thanks,
    Advance.
  • #769246
    Change Varchar type into Date/Time.
    Insert Date in the format of Date/Time in your database.
    Then use above query.

  • #769249
    declare @to int, @from int, @year int,@fromyear int, @toyear int
    set @to=3
    set @from=5
    set @fromyear=2016
    set @toyear=2017
    select * from Test where SUBSTRING(Month_Of_Upload,1,1) between @to and @from and
    SUBSTRING(Month_Of_Upload,3,4)=@fromyear

    in the above querry if i tried 3-2016 to 5-2016 its wokring fine but if i tried 3-2017 to 5-2017 its not working

    here Month_Of_Upload is varchar value saving values like'3-2016'
    suppose if want fetch records between '3-2016' to '3-2017' its not wokring


Sign In to post your comments