473,494 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Insert with subquery or single line statement?

In theory this is what I would like to do...but I get an error:
insert into users (homeid,carid) values(1, select carid from table2 where
field=x);
Since this doesn't work...I was wondering if I can use something like
this...but I want it to be one line (I'm using ADO).
select carid from table2 where field=x into var; insert into users
(homeid,carid) values(1,var);

Any ideas?

-bruce
Jul 23 '05 #1
2 1605
Got it:

insert into users (homeid,carid) select 1,carid from table2 where field=x;

That wasn't so bad!

-bruce
"Bruce D" <br*************@hotmail.com> wrote in message
news:11*************@corp.supernews.com...
In theory this is what I would like to do...but I get an error:
insert into users (homeid,carid) values(1, select carid from table2 where field=x);
Since this doesn't work...I was wondering if I can use something like
this...but I want it to be one line (I'm using ADO).
select carid from table2 where field=x into var; insert into users
(homeid,carid) values(1,var);

Any ideas?

-bruce

Jul 23 '05 #2
Bruce D wrote:
In theory this is what I would like to do...but I get an error:
insert into users (homeid,carid) values(1, select carid from table2
where
field=x);
Since this doesn't work...I was wondering if I can use something like
this...but I want it to be one line (I'm using ADO).
select carid from table2 where field=x into var; insert into users
(homeid,carid) values(1,var);


How about this:

insert into users (homeid,carid)
select 1, carid from table2 where field=x

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

121
9898
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
4
6433
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
11
6547
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
4
1907
by: solidsna2 | last post by:
Hi, I am relatively new to SQL. I am using SQL 2000. I am trying to Update a field base in a criteria in a scond table. UPDATE Tbl1 SET Tbl1.Row2 = '1' WHERE Tbl1.Row1...
0
1478
by: imtmub | last post by:
Hi All, when i am trying to insert records from excel sheet to wko table in my database. My Excel sheet contains 400 records. I am getting the error message. please check this code and advise me. ...
0
5685
debasisdas
by: debasisdas | last post by:
Using Subqueries ================== The sub query is often referred to as a nested SELECT, Sub - SELECT, or inner SELECT statement. The sub query executes once before the main query. The...
1
4129
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
8
5015
by: Red | last post by:
If auto-format is turned off in VS2008, there is apparently no way to indent a line. Under Tools->Options->Text Editor->C#->Formatting, there are three checkboxes. Unchecking those seems to cause...
0
1045
by: the_hawk_1 | last post by:
Hi! I've got a table where an index number is already given. I want to establish a trigger on a tmp table, so each time rows are inserted, the trigger verify the next number available in the...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.