0

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
1
  • 1
    having code that is formatted a little better makes it easier to see what @astander points out in his answer. sql query analyser doesn't care if column names are duplicated, try SELECT 1 as A, 1 AS A, 1 AS A but if you are trying to create a new table in Access, I'll bet that it cares. Commented Oct 28, 2009 at 11:41

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.