views:

295

answers:

1

Is there a way to do a conditional insert in the compact edition? I've tried two ways that I think would work on SqlServer:

INSERT INTO CUSTQUOTE (QTE_ID) VALUES (1) 
WHERE EXISTS(SELECT * FROM JOB WHERE JOB_NUMBER = 'EW090800345')
There was an error parsing the query. [ Token line number = 2,Token line offset = 1,Token in error = WHERE ]

IF EXISTS(SELECT * FROM JOB WHERE JOB_NUMBER = 'EW090800345')
BEGIN
    INSERT INTO CUSTQUOTE (QTE_ID) VALUES (1)
END
There was an error parsing the query. [ Token line number = 1,Token line offset = 1,Token in error = IF ]
+2  A: 

Why not :

INSERT INTO CUSTQUOTE (QTE_ID) 
SELECT 1
FROM JOB WHERE JOB_NUMBER = 'EW090800345'

or TOP 1 if JOB_NUMBER is not unique

CodeByMoonlight
Yes, that works, until you try to put parameters into it:INSERT INTO CUSTQUOTE (QTE_ID) SELECT @qte_id FROM JOB WHERE JOB_NUMBER = 'EW090800345'A parameter is not allowed in this location. Ensure that the '@' sign is in a valid location or that parameters are valid at all in this SQL statement.Any workaround for that?Colin
Colin