Home > DeveloperSection > Forums > Column 'Site_name' - ambiguous problem
Ankit Singh

Total Post:341

Points:2389
Posted on    September-30-2014 1:05 AM

 ASP.Net ASP.Net  MSSQL Server 
Ratings:


 3 Reply(s)
 763  View(s)
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



Chintoo Semi

Total Post:135

Points:947
Posted on    September-30-2014 1:07 AM

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



Pravesh Singh

Total Post:411

Points:2881
Posted on    September-30-2014 1:11 AM

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


Ankit Singh

Total Post:341

Points:2389
Posted on    September-30-2014 1:15 AM

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


Don't want to miss updates? Please click the below button!

Follow MindStick