Can I combine these two SQL queries into single query?
Can I combine these two SQL queries into single query?
query1
开发者_如何学GoALTER TABLE tableA
ADD datam INTEGER;
query2
UPDATE tableA SET datam = DateDiff("m",[call_date],#12/1/2009#);
no. the first one is not actually a 'query'. it is a statement of Data Definition Language
You could create a help PROCEDURE
to add the calculated default e.g. (ANSI-92 Query Mode Access Database Engine SQL syntax):
CREATE PROCEDURE CreateTableAThing
(
arg_my_key_column CHAR(10),
arg_call_date DATETIME
)
AS
INSERT INTO tableA (my_key_column, call_date, datam)
SELECT arg_my_key_column, arg_call_date, DATEDIFF('m', [arg_call_date], #2009-12-01 00:00:00#)
FROM MyOneRowAuxilliaryTable;
You could also create a helper functions for UPDATE
perhaps again to maintain the default.
You could then remove INSERT
/UPDATE
privileges from the table to force all applications and users to go via your helper procs to ensure the default is correctly applied.
Have you considered a macro that runs the queries? See http://office.microsoft.com/en-us/access-help/runsql-macro-action-HA001226285.aspx for more information.
精彩评论