• the exists generates the same fault. It is really strange. Two customers who does not exists in the second table where the count and exists statement has been tried out is being returned to my page. The only customers who should be returned should be those who exists in both tables.

    This is how it looks like now:

    select A.EKUNDEID,

    RTRIM(A.KUNDENR) as kundenr,

    RTRIM(B.ANAVNB) as navn,

    RTRIM(B.ABYB) as postnummerby,

    RTRIM(A.AEMAIL) as email,

    A.SAPKUNDENR,

    B.AKONTAKT

    from JB53000T A, JB53100T B

    where B.EKUNDEID = A.EKUNDEID'

    if(@kundenr <> '')

    set @sql = @sql + ' and A.kundenr like ''' + @kundenr + ''''

    ...

    ...

    other statements to complete the search for the customers

    ...

    set @sql = @sql + ' and exists(select * from CO55800T where KUNDE_NR collate SQL_Danish_Pref_CP1_CI_AS = A.kundenr)'

    ...

    exec(@sql)