Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
INSERT INTO TABLE1 (UID, LASTUPDATE, MODULEID,ENTRYNAME,NAME1,VALUE1) VALUES (NULL, 20150615050829, 2,'EEE','test','123') WHERE NOT EXISTS (SELECT * FROM TABLE1 WHERE ENTRYNAME = 'EEE')


Why am I getting an error?
Posted
Comments
F-ES Sitecore 15-Jun-15 6:59am    
And the error is.....?
Andy Lanng 15-Jun-15 7:00am    
what error are you getting?

I imagine that it's because your inserting a null into the unique id field. But that's a guess as you haven't given us ANY info.

If uid is an identity column then leave it out of the query all together
Michael Haephrati 15-Jun-15 7:10am    
near "WHERE": syntax error

1. Since there are a possible of 1,323,253,342 different errors, please post the error when you have one.
2. Your syntax is all wrong. You can't put a where on it unless you use a SELECT.

So either do as Solution 1 says or change it to:
SQL
INSERT INTO TABLE1 (UID, LASTUPDATE, MODULEID,ENTRYNAME,NAME1,VALUE1) 
SELECT NULL, 20150615050829, 2,'EEE','test','123' 
WHERE NOT EXISTS (SELECT * FROM TABLE1 WHERE ENTRYNAME = 'EEE')
 
Share this answer
 
Comments
Michael Haephrati 15-Jun-15 7:50am    
You can use WHERE if you use INSERT INTO. The error is "near "WHERE": syntax error"
ZurdoDev 15-Jun-15 7:52am    
If you use a SELECT statement. That's why you are getting a syntax error near where, because you can't use it that way.
Michael Haephrati 15-Jun-15 7:54am    
See this answer
INSERT tblSoftwareTitles (SoftwareName, SoftwareSystemType)
SELECT @SoftwareName,@SoftwareType
WHERE NOT EXISTS
( SELECT 1
FROM tblSoftwareTitles
WHERE Softwarename = @SoftwareName
AND SoftwareSystemType = @Softwaretype
);
from
http://stackoverflow.com/questions/17991479/insert-values-where-not-exists
ZurdoDev 15-Jun-15 7:58am    
Yes, that is what I said to do. Use SELECT. You are not using SELECT. You are using VALUES.
Michael Haephrati 15-Jun-15 7:59am    
What about VALUES (NULL, 20150615050829, 2,'EEE','test','123') ?
that would have to be part of a procedure with an IF statement in it I would think

IF NOT EXISTS (SELECT blah..blah...)
BEGIN
INSERT INTO blah... blah...
END

can do with a select

INSERT INTO table(blah1, blah2)
SELECT 'value1', 'value2'
WHERE NOT EXISTS (SELECT * FROM table WHERE blah1 = 'value1')

notice the SELECT keyword above replaces the VALUES keyword
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900