IF EXISTS: How do I write this in Access SQL

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

What is the equivalent code in Access SQL for the following T-SQL block:

IF EXISTS (SELECT * FROM orders WHERE amt > 10)
BEGIN
...do something
END
 
Hi,


I assume you mean Access+ JET (by opposition to Access+ MS SQL Server,
as example).


The "glue" is VBA, rather than a kind of an imperative extension to a
declarative language core (SQL). You supply the logic in VBA code, from a
module or otherwise, and from there, execute the SQL code


If 0=DCount("*", "order"", "amt>0") then
CurrentProject.Connection.Execute "... do something"
Else
...
End if


Sure, you can use

If 0=CurrentProject.Connection.Execute("SELECT COUNT(*) FROM orders
WHERE amt?0").Field(0).Value Then
...

Else
...
End If

instead of DCount, etc.


Hoping it may help,
Vanderghast, Access MVP
 
Thanks Michel


Michel Walsh said:
Hi,


I assume you mean Access+ JET (by opposition to Access+ MS SQL Server,
as example).


The "glue" is VBA, rather than a kind of an imperative extension to a
declarative language core (SQL). You supply the logic in VBA code, from a
module or otherwise, and from there, execute the SQL code


If 0=DCount("*", "order"", "amt>0") then
CurrentProject.Connection.Execute "... do something"
Else
...
End if


Sure, you can use

If 0=CurrentProject.Connection.Execute("SELECT COUNT(*) FROM orders
WHERE amt?0").Field(0).Value Then
...

Else
...
End If

instead of DCount, etc.


Hoping it may help,
Vanderghast, Access MVP
 
Back
Top