I have this statement buried in a sproc:
INSERT INTO PLAN_DEMAND ([YEAR], BOD_INDEX, SCEN_ID)
SELECT PLAN_SHIP.[YEAR], PLAN_SHIP.BOD_INDEX, 1
FROM PLAN_SHIP LEFT JOIN PLAN_DEMAND ON
PLAN_SHIP.[YEAR]=PLAN_DEMAND.[YEAR]
AND PLAN_SHIP.[BOD_INDEX]=PLAN_DEMAND.BOD_INDEX
WHERE PLAN_DEMAND.BOD_INDEX IS NULL
When I run the sproc in QA, the statements returns records to the grid, but does not insert them into the table. If I just copy the statement into QA and execute it, it works fine.
I'm sure it's something obvious (but not to me).
Any help would be much appreciated.Post the code for your sproc. Either a logical data flow error is preventing the statement from being executed, or you have something commented out of your production code.|||I tried to post the sproc, but I'm limited to posting 10K characters.
The sproc is about 15K.
However...
I commented out everything else in the sproc, execpt this one statement, and I still get the same thing.|||Humor me. Create this procedure:
CREATE PROCEDURE MYTEST
AS
BEGIN
INSERT INTO PLAN_DEMAND
([YEAR],
BOD_INDEX,
SCEN_ID)
SELECT PLAN_SHIP.[YEAR],
PLAN_SHIP.BOD_INDEX,
1
FROM PLAN_SHIP
LEFT JOIN PLAN_DEMAND
ON PLAN_SHIP.[YEAR]=PLAN_DEMAND.[YEAR]
AND PLAN_SHIP.[BOD_INDEX]=PLAN_DEMAND.BOD_INDEX
WHERE PLAN_DEMAND.BOD_INDEX IS NULL
END
Execute it, and let me know what you get.|||Works perfectly... as- I'm sure- you expected.
hmmm...
Since the 2 statements are identical, the problem must lie elsewhere in the sproc. But then, why didn't it work when I commented out everything but this statement? Since the sproc is really just a series of insert/updates, I'll try posting one section at a time to a new sproc until I see the problem again.|||Do you have GO statements in your sproc? Those are command terminators rather than SQL commands, and are not affected by commenting.|||I have 1 go statement, at the very end of the sproc.|||OK Blind dude... Here's what I found:
I tried to parse my original statement to look like yours, just for grins.
After converting the first the first line from this:
INSERT INTO PLAN_DEMAND ([YEAR], BOD_INDEX, SCEN_ID)
to this:
INSERT INTO PLAN_DEMAND
([YEAR], BOD_INDEX, SCEN_ID)
I got: ILLEGAL SYNTAX NEAR [YEAR]
Everything looked ok, so I deleted the line: INSERT INTO PLAN_DEMAND
and just retyped it. Works fine now. Must've been some illegal character
between DEMAND and ([YEAR])
Thanks for your help
No comments:
Post a Comment