Comparision of a datetime variable against a column of the type nvarchar

  • Hello All,

    I have a table like this:

    MinionRpt

    (

    Id [int], FullName [nvarchar](100), ..., EstDate [nvarchar](100)

    )

    If you noticed, the column [EstDate] (Estimated Date) is nvarchar(100). It need not always contain a date.

    Now I gotta query like this:

    select * from MinionRpt where DateDiff (d, EstDate, @StartDate) <= 0 and DateDiff(d, EstDate, @EndDate) >= 0

    The problem is when we have invalid formats or gibberish for EstDate in some records, the query would throw an error.

    I have no control over the existing data or any future data or even the schema design.

    Can some one tell me, how I should go about it?

    Thanks in advance,

    Venkat R Prasad.

  • Duplicate post. No replies here please.

    Replies belong here: http://www.sqlservercentral.com/Forums/Topic1353333-392-1.aspx


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

Viewing 2 posts - 1 through 1 (of 1 total)

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