Matching Dates

sql server Austria
  • 14 years ago


    I'm trying to filter public holidays out of a recordset and am having trouble.

    I build a varchar of dates from 1 table  and check all records from another table to see if a datefield is IN the varchar - but for somereason it isnt working...I'm really stuck

    set nocount on

    DECLARE @HolsList varchar(5000)
    SElECT @HolsList = COALESCE(@HolsList + ', ', '') + '''' + CONVERT(VARCHAR(8), HolidayDate, 3) + ''''
    FROM tblPublicHolidays


    SELECT LoadedDate, CONVERT(VARCHAR(8), LoadedDate, 3)  from CaseDetailsTemp
    WHERE CONVERT(VARCHAR(8), LoadedDate, 3) IN (@HolsList)
    --where CONVERT(VARCHAR(8), LoadedDate, 3) IN ('08/05/06','02/01/06')

    The rem'd out lasdt line works just fine, I have tried every type of format cast and convert on the 'LoadedDate' and on the @HolsList ... But even tho the Select @HolsList shows me exactly what I expected, a string of dates that are comma seperated and each enclosed by apostrophes.


    Help please!!!

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Before software should be reusable, it should be usable.” - Ralph Johnson