views:

333

answers:

2

Hey, I am using iBATIS with SQL Server Compact Edition 3.5 and try to do a subselect

INSERT INTO FORMINSTANCE (ID, ID_FORM) 
  SELECT #ID#, f.ID 
  FROM FORM f 
  WHERE ID_PROCESS='10804'

When I commit the transaction I get an SqlCeException (SSCE_M_QP_PARAMETERNOTALLOWED).

That the Symbol '@' is on the wrong place. I think this is the #ID# which is unpredicted in SELECT. #ID# is not the name of the column, it's the value that should be inserted into FORMINSTANCE How can i fix this?

ty

+1  A: 

If the # part of the column name…

INSERT INTO FORMINSTANCE (ID, ID_FORM) 
SELECT [#ID#], f.ID 
FROM   FORM f 
WHERE  ID_PROCESS='10804'

If for some odd reason you wanted a dynamic column to be selected at position #1 (not that I really think that this is what you're up to, but anyway), you could get away with:

INSERT INTO FORMINSTANCE (ID, ID_FORM) 
SELECT 
  CASE 
    WHEN @ID = 'foo' THEN foo
    WHEN @ID = 'bar' THEN bar
    ELSE NULL
  END, 
  f.ID 
FROM
  FORM f 
WHERE
  ID_PROCESS='10804'
Tomalak
#ID# is not the name of the column, it's the value that should be inserted into FORMINSTANCE
codedevour
Then it's a string and should be denoted as `'#ID#'`, shouldn't it?
Tomalak
You're right but this also leads to the same exception
codedevour
Does SELECT query itself work?
Tomalak
Yes if i try it with, it works: INSERT INTO FORMINSTANCE (ID, ID_FORM) SELECT 'UUUID', f.ID FROM FORM f WHERE ID_PROCESS='10804'
codedevour
Hm, if you "try it with" *what*? :) (Does that mean it actually works now?)
Tomalak
codedevour
Hm, so '#ID#' is a placeholder for a *real* value in iBATIS? Because to T-SQL it does not have a special meaning (AFAIK), and you should go with *actual* @-parameters instead of string expansion.
Tomalak
A: 

I don't think you can if #ID# isn't in the FORM table (ie, a parameter). Even if #ID# was in the standard parameter format of @ID, SQL Server CE doesn't support named parameters in that location.

CodeByMoonlight
Hmm then maybe my subselect is wrong structured? But it works if i don't use the named parameters and try instead of #ID# -> 'UUID'. Than the insert works.
codedevour