Insert into SQL database only if does not exist2019 Community Moderator Electionreturn if a success vba sqlHow do I perform an IF…THEN in an SQL SELECT?Add a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeHow to check if a column exists in a SQL Server table?Check if table exists in SQL ServerHow to concatenate text from multiple rows into a single text string in SQL server?LEFT JOIN vs. LEFT OUTER JOIN in SQL ServerInserting multiple rows in a single SQL query?Insert results of a stored procedure into a temporary tableHow do I UPDATE from a SELECT in SQL Server?

Can the Witch Sight warlock invocation see through the Mirror Image spell?

If nine coins are tossed, what is the probability that the number of heads is even?

Should we avoid writing fiction about historical events without extensive research?

Are these two graphs isomorphic? Why/Why not?

Rationale to prefer local variables over instance variables?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

"If + would" conditional in present perfect tense

Why restrict private health insurance?

Are small insurances worth it?

Create chunks from an array

Was it really inappropriate to write a pull request for the company I interviewed with?

What will happen if my luggage gets delayed?

How do we create new idioms and use them in a novel?

Playing a 7-string guitar song on a 6-string guitar

How to educate team mate to take screenshots for bugs with out unwanted stuff

Movie: boy escapes the real world and goes to a fantasy world with big furry trolls

What does *dead* mean in *What do you mean, dead?*?

Is there a math expression equivalent to the conditional ternary operator?

How can I portion out frozen cookie dough?

Is it a Cyclops number? "Nobody" knows!

Is there a way to make cleveref distinguish two environments with the same counter?

Cycles on the torus

Are all players supposed to be able to see each others' character sheets?

Does the US political system, in principle, allow for a no-party system?



Insert into SQL database only if does not exist



2019 Community Moderator Electionreturn if a success vba sqlHow do I perform an IF…THEN in an SQL SELECT?Add a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeHow to check if a column exists in a SQL Server table?Check if table exists in SQL ServerHow to concatenate text from multiple rows into a single text string in SQL server?LEFT JOIN vs. LEFT OUTER JOIN in SQL ServerInserting multiple rows in a single SQL query?Insert results of a stored procedure into a temporary tableHow do I UPDATE from a SELECT in SQL Server?










0















Using VBA to insert into microsoft sql database



SELECT ALL *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227')
ORDER BY [ID] DESC


for example, the above, if insert a vessel that matches the name and date +/- 3 days, let it not as it matches something already in the DB










share|improve this question
























  • @Larnu ALL * is valid T-SQL syntax, although usually redundant

    – k29
    Mar 6 at 14:07












  • That between statement may not be doing quite what you think. If the datatype of your day column is a datetime it will not return any rows that on the +3 days because the timestamp would be greater than the beginning of the day. When it comes to date calculations (and many more things) between can really be problematic. sqlblog.org/2011/10/19/…

    – Sean Lange
    Mar 6 at 14:34















0















Using VBA to insert into microsoft sql database



SELECT ALL *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227')
ORDER BY [ID] DESC


for example, the above, if insert a vessel that matches the name and date +/- 3 days, let it not as it matches something already in the DB










share|improve this question
























  • @Larnu ALL * is valid T-SQL syntax, although usually redundant

    – k29
    Mar 6 at 14:07












  • That between statement may not be doing quite what you think. If the datatype of your day column is a datetime it will not return any rows that on the +3 days because the timestamp would be greater than the beginning of the day. When it comes to date calculations (and many more things) between can really be problematic. sqlblog.org/2011/10/19/…

    – Sean Lange
    Mar 6 at 14:34













0












0








0








Using VBA to insert into microsoft sql database



SELECT ALL *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227')
ORDER BY [ID] DESC


for example, the above, if insert a vessel that matches the name and date +/- 3 days, let it not as it matches something already in the DB










share|improve this question
















Using VBA to insert into microsoft sql database



SELECT ALL *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227')
ORDER BY [ID] DESC


for example, the above, if insert a vessel that matches the name and date +/- 3 days, let it not as it matches something already in the DB







sql-server excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Pᴇʜ

23.7k62952




23.7k62952










asked Mar 6 at 13:59









Ryan JacquesRyan Jacques

12




12












  • @Larnu ALL * is valid T-SQL syntax, although usually redundant

    – k29
    Mar 6 at 14:07












  • That between statement may not be doing quite what you think. If the datatype of your day column is a datetime it will not return any rows that on the +3 days because the timestamp would be greater than the beginning of the day. When it comes to date calculations (and many more things) between can really be problematic. sqlblog.org/2011/10/19/…

    – Sean Lange
    Mar 6 at 14:34

















  • @Larnu ALL * is valid T-SQL syntax, although usually redundant

    – k29
    Mar 6 at 14:07












  • That between statement may not be doing quite what you think. If the datatype of your day column is a datetime it will not return any rows that on the +3 days because the timestamp would be greater than the beginning of the day. When it comes to date calculations (and many more things) between can really be problematic. sqlblog.org/2011/10/19/…

    – Sean Lange
    Mar 6 at 14:34
















@Larnu ALL * is valid T-SQL syntax, although usually redundant

– k29
Mar 6 at 14:07






@Larnu ALL * is valid T-SQL syntax, although usually redundant

– k29
Mar 6 at 14:07














That between statement may not be doing quite what you think. If the datatype of your day column is a datetime it will not return any rows that on the +3 days because the timestamp would be greater than the beginning of the day. When it comes to date calculations (and many more things) between can really be problematic. sqlblog.org/2011/10/19/…

– Sean Lange
Mar 6 at 14:34





That between statement may not be doing quite what you think. If the datatype of your day column is a datetime it will not return any rows that on the +3 days because the timestamp would be greater than the beginning of the day. When it comes to date calculations (and many more things) between can really be problematic. sqlblog.org/2011/10/19/…

– Sean Lange
Mar 6 at 14:34












1 Answer
1






active

oldest

votes


















0














Use IF NOT EXISTS and remove the ORDER BY



IF NOT EXISTS(SELECT *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227'))
BEGIN
--your insert statement
END





share|improve this answer

























  • Fantastic, is there a way to get a response if it does exist? i.e. Msgbox "this is already in the database"

    – Ryan Jacques
    Mar 6 at 16:10











  • This is being answered in a follow up question from the OP here

    – Sean Lange
    Mar 6 at 16:46










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024882%2finsert-into-sql-database-only-if-does-not-exist%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Use IF NOT EXISTS and remove the ORDER BY



IF NOT EXISTS(SELECT *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227'))
BEGIN
--your insert statement
END





share|improve this answer

























  • Fantastic, is there a way to get a response if it does exist? i.e. Msgbox "this is already in the database"

    – Ryan Jacques
    Mar 6 at 16:10











  • This is being answered in a follow up question from the OP here

    – Sean Lange
    Mar 6 at 16:46















0














Use IF NOT EXISTS and remove the ORDER BY



IF NOT EXISTS(SELECT *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227'))
BEGIN
--your insert statement
END





share|improve this answer

























  • Fantastic, is there a way to get a response if it does exist? i.e. Msgbox "this is already in the database"

    – Ryan Jacques
    Mar 6 at 16:10











  • This is being answered in a follow up question from the OP here

    – Sean Lange
    Mar 6 at 16:46













0












0








0







Use IF NOT EXISTS and remove the ORDER BY



IF NOT EXISTS(SELECT *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227'))
BEGIN
--your insert statement
END





share|improve this answer















Use IF NOT EXISTS and remove the ORDER BY



IF NOT EXISTS(SELECT *
FROM [MarketAnalysis].[dbo].[ReviewDatabase]
WHERE [VESSEL] = 'BOATY'
AND [LOAD DATE] BETWEEN DATEADD(day, -3,'20190227') AND DATEADD(day, +3,'20190227'))
BEGIN
--your insert statement
END






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 6 at 17:09

























answered Mar 6 at 14:09









k29k29

311115




311115












  • Fantastic, is there a way to get a response if it does exist? i.e. Msgbox "this is already in the database"

    – Ryan Jacques
    Mar 6 at 16:10











  • This is being answered in a follow up question from the OP here

    – Sean Lange
    Mar 6 at 16:46

















  • Fantastic, is there a way to get a response if it does exist? i.e. Msgbox "this is already in the database"

    – Ryan Jacques
    Mar 6 at 16:10











  • This is being answered in a follow up question from the OP here

    – Sean Lange
    Mar 6 at 16:46
















Fantastic, is there a way to get a response if it does exist? i.e. Msgbox "this is already in the database"

– Ryan Jacques
Mar 6 at 16:10





Fantastic, is there a way to get a response if it does exist? i.e. Msgbox "this is already in the database"

– Ryan Jacques
Mar 6 at 16:10













This is being answered in a follow up question from the OP here

– Sean Lange
Mar 6 at 16:46





This is being answered in a follow up question from the OP here

– Sean Lange
Mar 6 at 16:46



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024882%2finsert-into-sql-database-only-if-does-not-exist%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved