I thought a table variable would cure my woes, but that doesn't seem to be a viable option with a bulk insert. I have the following stored procedure that works fine when I execute it (with admin access), but when my user runs it they recieve the following error: "The current user is not the database or object owner of table #Critical. Cannot perform SET operation." The user has execute permission on the procedure and I'm kind of at a loss.
CREATE procedure spoplst_criticaltotals
as
create table #OPLST(
(BATCH varchar(9),
SUBNO varchar(15),
PCNTLNO varchar(38),
CLAIMNO varchar(16),
CPLAN varchar(10),
SERVDATE datetime,
RECDATE datetime,
IN_FILE varchar(15))
bulk insert #OPLST
from '\\SERVER\oplst.txt'
with (FIELDTERMINATOR = ',', ROWTERMINATOR = '\r')
insert OPLST
(BATCHKEY,
BATCH,
PCNTLNO,
CLAIMNO,
CPLAN,
SERVDATE,
RECDATE,
INFILE)
select BATCHKEY = BATCH+CPLAN+RECDATE,
BATCH = BATCH,
PCNTLNO = convert(varchar(5), replace(replace(ltrim(replace(replace(PCNTLNO, ' ', '^'), '0', ' ')), ' ', '0'), '^', ' ')),
CLAIMNO = convert(varchar(5), replace(replace(ltrim(replace(replace(CLAIMNO, ' ', '^'), '0', ' ')), ' ', '0'), '^', ' ')),
CPLAN = CPLAN,
SERVDATE = convert(datetime, RECDATE, 112),
RECDATE = convert(datetime, RECDATE, 112),
IN_FILE = IN_FILE
from #Critical
GO
CREATE procedure spoplst_criticaltotals
as
create table #OPLST(
(BATCH varchar(9),
SUBNO varchar(15),
PCNTLNO varchar(38),
CLAIMNO varchar(16),
CPLAN varchar(10),
SERVDATE datetime,
RECDATE datetime,
IN_FILE varchar(15))
bulk insert #OPLST
from '\\SERVER\oplst.txt'
with (FIELDTERMINATOR = ',', ROWTERMINATOR = '\r')
insert OPLST
(BATCHKEY,
BATCH,
PCNTLNO,
CLAIMNO,
CPLAN,
SERVDATE,
RECDATE,
INFILE)
select BATCHKEY = BATCH+CPLAN+RECDATE,
BATCH = BATCH,
PCNTLNO = convert(varchar(5), replace(replace(ltrim(replace(replace(PCNTLNO, ' ', '^'), '0', ' ')), ' ', '0'), '^', ' ')),
CLAIMNO = convert(varchar(5), replace(replace(ltrim(replace(replace(CLAIMNO, ' ', '^'), '0', ' ')), ' ', '0'), '^', ' ')),
CPLAN = CPLAN,
SERVDATE = convert(datetime, RECDATE, 112),
RECDATE = convert(datetime, RECDATE, 112),
IN_FILE = IN_FILE
from #Critical
GO