简体   繁体   中英

how to use variables in SQL statement (MS Access)

How can I declare a variable that contain the following function:

DSUM function

and put this variable in SQL statement like that :-

update Tbl-1
set [Field1] = (the variable that I want to declare)
where ...
  and etc.

Declare? Anyway, you can pull a value with DSum :

update Tbl-1
set [Field1] = DSum("[Amount]", "SomeOtherTable", "[SomeField] = SomeValue")

The type of logic that you can apply is not possible, a variable that store a function? I only know the case of <> in C#, but your case is totally different.

If you read the next article you will find an easy explanation: http://www.techonthenet.com/access/functions/domain/dsum.php

Then you should incorporate in the Set part directly the operation that you need, in this case:

update Tbl-1 set [Field1] = (The operation that you want to apply on the Field1) where ... and etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM