sql server - Ambiguous column name error getting while executing stored procedure -


i have stored procedure this:

alter procedure [dbo].[parkingdeatailsreportcheck]     @locid integer ,     @startdate nvarchar(100) ,     @enddate nvarchar(100)      begin         declare @cols nvarchar(max) ,             @query nvarchar(max)          select  @cols = stuff((select distinct                                         ',' + quotename(vtype)                                    vtype_tbl                           xml path('') ,                                   type   ).value('.', 'nvarchar(max)'), 1, 1, '')         set @query = 'select locname,date, ' + @cols             + '  ( select l.locname, v.vtype, convert(date, dtime) date  transaction_tbl t  inner join vtype_tbl v   on t.vtid = v.vtid  join location_tbl l on t.locid=l.locid     locid='             + cast(@locid varchar(max)) + ' , dtime between '''             + @startdate + ''' , ''' + @enddate + '''  ) d pivot   (                     count(vtype)                 vtype in (' + @cols + ')     ) p '         execute(@query)     end 

while executing stored procedure getting error this:ambiguous column name 'locid'. expected output this:

 locationname   date       emaar staff lost ticket normal      vip         vvip                 ---------- ----------- ----------- ----------- ----------- -----------  fashion         2013-05-08      1           0           2           0           1  fashion         2013-05-25      0           0           1           1           0  fashion        2013-05-27       0           0           17          2           1    

you have

join location_tbl l on t.locid=l.locid     locid=' 

change

join location_tbl l on t.locid=l.locid     l.locid=' 

you need table alias, it's in dynamic sql after where.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -