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?
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
add a comment |
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
@LarnuALL *
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
add a comment |
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
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
sql-server excel vba
edited 2 days ago
Pᴇʜ
23.7k62952
23.7k62952
asked Mar 6 at 13:59
Ryan JacquesRyan Jacques
12
12
@LarnuALL *
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
add a comment |
@LarnuALL *
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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
@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