COLUMN 'SITE_NAME' - AMBIGUOUS PROBLEM

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 1007  View(s)
Ratings:
Rate this:

I have inner join two tables and display. I tried the given below code. But it generate on error "Ambiguous Column site_name' "

 

SELECT site_name, Mains_Run_Hrs, DG_Run_Auto_Mode, Battery_Run_Hrs,Solar_Run_hrs

FROM tbl_runtime_report INNER JOIN tbl_site_details

ON tbl_runtime_report.Site_ID=tbl_site_details.site_id

WHEREsite_name=@site_name

  1. Chintoo Semi

    Post:135

    Points:947
    Re: Column 'Site_name' - ambiguous problem

    Hi ankit,

    If site_name resides in both tables, you need to specify which version you are querying i.e.

     

    WHERE tbl_runtime_report.site_name = @site_name

    Alternatively, you could use an alias

     

    SELECT rt.site_name, ...

    FROM tbl_runtime_report rt ...

    WHERE rt.site_name = @site_name


  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Column 'Site_name' - ambiguous problem

    SELECT  Report.ColumnName,Details.ColumnName

    FROM tbl_runtime_report Report

         INNER JOIN tbl_site_details  Details ON Report.Site_ID=Details .site_id

    WHERE Report.site_name=@site_nam

  1. Ankit Singh

    Post:341

    Points:2389
    Re: Column 'Site_name' - ambiguous problem

    select top (1) Dg_energy_daily, Load_energy_daily, mains_energy_daily,solar_energy_daily 

    From tbl_energy_report

    inner join tbl_site_details

    ON tbl_energy_report.Site_ID=tbl_site_details.site_id

    where tbl_site_details.site_name=@site_name order by sl_no desc

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!