473,480 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditional insert?

I need to do in SQL the following psuedo-code, and I'm stuck:

IF ((COUNT(*) FROM a WHERE column_a=1)>0)
THEN
INSERT INTO TABLE b
ENDIF
Aug 18 '05 #1
1 6955
hoonew wrote:
I need to do in SQL the following psuedo-code, and I'm stuck:

IF ((COUNT(*) FROM a WHERE column_a=1)>0)
THEN
INSERT INTO TABLE b
ENDIF


create table a (column_a integer);
create table b (foo varchar(10));
insert into a (column_a) values (1), (1);

insert into b (foo)
select distinct 'foo' as foo
from a where column_a = 1;
....one record inserted, because of distinct.

insert into b (foo)
select distinct 'foo' as foo
from a where column_a = 2;
....zero records inserted, because no records in `a` match.

Bill
Aug 18 '05 #2

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

Similar topics

1
8624
by: Bob | last post by:
I need to know if there is a better way to construct this SQL statement. (Error handling is omitted) MS SQL Server 2000 Insert into FSSUTmp Select a.acct_no, a.ac_nm, a.ac_type, 10, -1, -1...
2
10449
by: jim_geissman | last post by:
What does "conditional" mean as a command? sp_who2 reports this for some sessions, along with "insert" etc. Thanks, Jim Geissman
9
1697
by: pk | last post by:
Here is my problem. I want to make a webapp that will basically take the work out of finding what tool works for what situation. There are 5 factors that go into tool selection. 1)Material...
8
1659
by: Drew | last post by:
I am building an application for keeping track of user permissions here at work. I have built the interfaces, and am now working on the processing page for inserting to the database. I am having...
1
4941
by: GGerard | last post by:
Hello Is there a way to use a variable in the Conditional Formatting of a Textbox? Example : I want the background of a textbox in a continuous form to change color when the value of...
3
1603
by: John | last post by:
Hi Is there a way to conditionally include parts of code in a vb.net project? I am creating an app for two clients with slightly different requirements. I figure if I can set the condition at...
9
4026
by: cavassinif | last post by:
I need to dynamic select a column in which insert a vale based on a parameter value, I have this code, but it throws an incorrect syntax error. How do I dinamically select a column to insert...
4
1912
by: a | last post by:
I'm having trouble testing a custom object. I've tried many different approaches. One is shown below. The XML below shows the state of the object and I'm trying to test for that state, ie there...
3
3733
by: msrviking | last post by:
Hello everybody, After several attempts of writing the query, I had to post my requirement in the forum. Here is what I have, what I need and what I did. Table A Col1 Col2 1 Nm1
1
1548
by: Mark A | last post by:
I've got a continuous form that is just for display, so hence all items on it are set to Enabled = No, Locked = Yes. This has the desired effect of making the item unclickable - exactly what I...
0
7039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
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
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4770
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
4476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2992
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...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
176
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.