views:

42

answers:

1

I am trying to export the following data in the query from ms sql server to access, it says an error "Field wkid already exists in the table results"

when i try to execute the same using sql query analyser, its not giving any error.i am getting the results in the grid

Select a.wkid,a.stid,a.pfid,pf.pfname,a.modid,mm.md,a.catid,
[sp],revenue,profit,wkid  from
(select stid,modid,pfid,catid,
[sp],revenue,profit,wkid 
from dbo.modspsal
where wkid >= 200934 and wkid <= 201033 and 
catid in (20001,20002,20003,20004,20005,20006)) as a
left join mml mm on 
mm.modid=a.modid
left join (select distinct pfid,[pf name] as pfname from mml) as pf
on pf.pfid=a.pfid
order by a.wkid,stid,catid,a.pfid,a.modid
+2  A: 

When you are exporting to excel you require to have unique column names. You have wkid specified 2.

Select  a.wkid,--HERE
     a.stid,
     a.pfid,
     pf.pfname,
     a.modid,
     mm.md,
     a.catid, 
     [sp],
     revenue,
     profit,
     wkid  --HERE
from    (
      select stid,
        modid,
        pfid,
        catid, 
        [sp],
        revenue,
        profit,
        wkid  
      from dbo.modspsal 
      where wkid >= 200934 
      and  wkid <= 201033 
      and  catid in (20001,20002,20003,20004,20005,20006)
     ) as a  left join 
     mml mm ON mm.modid=a.modid  left join 
     (
      select distinct 
        pfid,
        [pf name] as pfname 
      from mml
     ) as pf on pf.pfid=a.pfid 
order by a.wkid,stid,catid,a.pfid,a.modid

Remove the last wkid and you should be fine.

astander