Ambiguos Colum Name Sender error

  • hi guys,

    I dont get this stupid error. Hope u can find out whats wrong.

    My query is

    SELECT @sql = 'SELECT DISTINCT Case30.Case_no#,Case30.Last_name,Case30.[First Name],Case30.Determination,Case30.Sender,Case30.[Case Type],Case30.Date,Case30.[Qwik Due],Case30.[Qwik sent date],Case30.[Final due],Case30.[Final sent date],Case30.[on hold code],tblFileNames.reportid,userviewed.viewid,tblFileNames.type FROM tblFileNames Left Outer Join Case30 ON Case30.Case_no# = tblFileNames.case_id Left Outer join userviewed ON tblFileNames.reportid = userviewed.reportid '+@return+@where_clause+@return+

    'UNION '+@return+

    'SELECT DISTINCT CASEOLDR.Case_no#,CASEOLDR.Last_name,CASEOLDR.[First Name],CASEOLDR.Determination,CASEOLDR.Sender,CASEOLDR.[Case Type],CASEOLDR.Date,CASEOLDR.[Qwik Due],CASEOLDR.[Qwik sent date],CASEOLDR.[Final due],CASEOLDR.[Final sent date],CASEOLDR.[on hold code],tblFileNAmes.reportid,userviewed.viewid,tblFileNames.type FROM tblFileNames Left Outer Join CASEOLDR ON CASEOLDR.Case_no# = tblFileNames.case_id Left Outer join userviewed ON tblFileNames.reportid = userviewed.reportid'+@return+@where_clause

    Hope somebody can tell me why does one get this error?There is no error in the name of the column.So think something else.

  • Look for a non-fully-qualified field of Sender in your WHERE clause. The SELECTs look fine.

  • what do u mean by

    non-fully-qualified field of Sender in where clause.

    CASE WHEN @param5 IS NOT NULL THEN @return+' AND Sender LIKE '''+@param5+'%''' ELSE '' END+

    this is my where clause for Sender but i didnot find anything wrong in it? I would really appreciate if u can go into little detail of it.

  • You need to qualify the Sender field with the tablename it belongs to that you are searching on. SQL is complaining that it has found two tables in your FROM clause that contain a Sender field; and it is waiting for you to specify the exact table and field you are basing your WHERE clause on. It looks like you should have:

    
    
    CASE WHEN @param5 IS NOT NULL THEN @return+' AND CASEOLDR.Sender LIKE '''+@param5+'%''' ELSE '' END+

    as your WHERE clause.

  • As jpipes stated, that error means there are two or more possible columns with that name and you need to identify which one the query is to use.

    Specifically, you have:

    CASE30.Sender

    CASEOLDR.Sender

    Two columns with the same name of sender. Your WHERE clause doesn't identify WHICH one to use.

    -SQLBill

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

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