Append Query Help Please

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have Table1 which has 50 records that I want to insert into Table2 which is
straight forward with an INSERT INTO Table1 (...) SELECT (...) FROM Table2.
However in on of the fields I need to pass in a VB variable for each of the
50 records thus making them specific to that variable. In the code below I
would also like to add a value to the field called CONTRACT which would be
added to dbo_BusinessRules but I can't figure out how to do it?

My code from within VB looks like this and this works:
INSERT INTO dbo_BusinessRules ( [SR], [PR], [PA], [RULE_CODE], [RULE_DESC],
[RULE_TYPE] )
SELECT TLC_RULES.SR, TLC_RULES.PR, TLC_RULES.PA, TLC_RULES.RULE_CODE,
TLC_RULES.RULE_DESC, TLC_RULES.RULE_TYPE
FROM TLC_RULES
 
Sorry I didn't even understand my first post :-(

I have TLC_RULES which has 50 records that I want to insert into
dbo_BusinessRules. This is straight forward with an INSERT INTO Table1
(...) SELECT (...) FROM Table2.

However in one of the fields (which is empty in TLC_RULES, I need to pass in
a VB variable for each of the 50 records.
In the code below I would like to add a value to the field called CONTRACT
which would be added to dbo_BusinessRules but I can't figure out how to do
it?

My code from within VB looks like this and this works:
INSERT INTO dbo_BusinessRules ( [SR], [PR], [PA], [RULE_CODE], [RULE_DESC],
[RULE_TYPE] )
SELECT TLC_RULES.SR, TLC_RULES.PR, TLC_RULES.PA, TLC_RULES.RULE_CODE,
TLC_RULES.RULE_DESC, TLC_RULES.RULE_TYPE
FROM TLC_RULES
 
Sorry I didn't even understand my first post :-(

I have TLC_RULES which has 50 records that I want to insert into
dbo_BusinessRules. This is straight forward with an INSERT INTO Table1
(...) SELECT (...) FROM Table2.

However in one of the fields (which is empty in TLC_RULES, I need to pass in
a VB variable for each of the 50 records.
In the code below I would like to add a value to the field called CONTRACT
which would be added to dbo_BusinessRules but I can't figure out how to do
it?

My code from within VB looks like this and this works:
INSERT INTO dbo_BusinessRules ( [SR], [PR], [PA], [RULE_CODE], [RULE_DESC],
[RULE_TYPE] )
SELECT TLC_RULES.SR, TLC_RULES.PR, TLC_RULES.PA, TLC_RULES.RULE_CODE,
TLC_RULES.RULE_DESC, TLC_RULES.RULE_TYPE
FROM TLC_RULES

You could create an expression for CONTRACT and use your VBA function
to do it. Of course, it would be faster if you didn't need to use
VBA, so if you can do it in SQL, I would do that first. (also makes it
more portable).

Your SQL would look something like this:
INSERT INTO dbo_BusinessRules ( [SR], [PR], [PA], [RULE_CODE],
[RULE_DESC],
[RULE_TYPE], [CONTRACT] )
SELECT TLC_RULES.SR, TLC_RULES.PR, TLC_RULES.PA,
TLC_RULES.RULE_CODE,
TLC_RULES.RULE_DESC, TLC_RULES.RULE_TYPE, MyContractFunction([arg1],
[arg2]...)
FROM TLC_RULES
 
Back
Top