By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

SQL statements (INSERT...INTO)

P: n/a
Is it possible when coding a SQL statement to use variables within an
INSERT INTO statement i.e the variables contain some data I wish to
insert along with the standard entity.attribute data?

E.G.

2 Entites/Tables, tblA and tblB. Both have the same Attributes/fields
'Fname' and 'Lname. So my SQL statement looks like this:-

"INSERT INTO tblB (Fname, Lname) SELECT tblA.Fname FROM tblA
WHERE tblA.Fname='" & strFname & "' VALUES(" & strLname & ");"

So I know that the WHERE clause works using the variable 'strFname' as
a container for the search criteria but is there a way of getting the
variable 'strLname' to insert with the rest of the data?

Any help would be appreciated

Cheers,

Kelvin
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Kelvin wrote:
Is it possible when coding a SQL statement to use variables within an
INSERT INTO statement i.e the variables contain some data I wish to
insert along with the standard entity.attribute data?

E.G.

2 Entites/Tables, tblA and tblB. Both have the same Attributes/fields
'Fname' and 'Lname. So my SQL statement looks like this:-

"INSERT INTO tblB (Fname, Lname) SELECT tblA.Fname FROM tblA
WHERE tblA.Fname='" & strFname & "' VALUES(" & strLname & ");"

So I know that the WHERE clause works using the variable 'strFname' as
a container for the search criteria but is there a way of getting the
variable 'strLname' to insert with the rest of the data?


"INSERT INTO tblB (Fname, Lname) SELECT tblA.Fname, '"& strLname &"'
FROM tblA
WHERE tblA.Fname='" & strFname & "' VALUES(" & strLname & ");"

should do the trick
--
Bas Cost Budde

Nov 12 '05 #2

P: n/a
starwars <no****@tatooine.homelinux.net> wrote:
Comments: This message did not originate from the Sender address above.
It was remailed automatically by anonymizing remailer software.


Folks, If you are new to the newsgroups this person is not at all representative of
the assistance you will receive.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 12 '05 #3

P: n/a
If you use SELECT INTO then you should be able to do this no problem.
You could also execute the select statement, open it into a static
recordset and do a recordcount...
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.