473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Insert Into Select trouble

I've tried for hours... and my issue is this:

Table 1 has FirstName, LastName, Address, Birthday, (and other
columns)
Table 2 has FirstName, LastName, Address, Birthday, (and other
columns)

Most of Table1.Birthday is null. Some are not.
All of Table2.Birthday has valid Birthdays.

I want to insert Table2.Birthday into Table1.Birthday only where
Table1.Birthday is null.

Any help is appreciated.
Jul 21 '08 #1
3 2295
Oh... and here's the closest I have come..

insert into table1 (birthday)
SELECT birthday
FROM table2,table1
WHERE (table1.firstname=table2.firstname AND
table1.lastname=table2.lastname AND table1.address=table2.address)
AND table1.birthday is null

If you delete the first line, I get the data I am looking to update
Table1 with.
Jul 21 '08 #2
Here is what worked

Update Table1
set Table1.Birthday=Table2.Birthday
From table1,table2
where (table1.firstname=table2.firstname AND
table1.lastname=table2.lastname AND table1.address=table2.address)
and table1.birthday is null
Jul 21 '08 #3
On Sun, 20 Jul 2008 23:31:30 -0700 (PDT), Brian <ey****@gmail.com>
wrote:
>Here is what worked

Update Table1
set Table1.Birthday=Table2.Birthday
From table1,table2
where (table1.firstname=table2.firstname AND
table1.lastname=table2.lastname AND table1.address=table2.address)
and table1.birthday is null
That uses syntax proprietary to SQL Server. In standard SQL you could
use:

UPDATE Table1
SET Table1.Birthday =
(SELECT Table2.Birthday
FROM Table2
WHERE table1.firstname = table2.firstname
AND table1.lastname = table2.lastname
AND table1.address = table2.address)
WHERE table1.birthday is null

Roy Harvey
Beacon Falls, CT
Jul 21 '08 #4

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

Similar topics

4
by: DTB | last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to replicate a BEFORE UPDATE trigger from ORACLE. Here is a sample of the ORACLE BEFORE UPDATE trigger: CREATE TRIGGER myTRIGGER ON...
14
by: Andre | last post by:
Hello Can anyone help me translate this from access so that it can work in mssql (i need to get next value, but cannot use identity as if row is deleted, another must get new next column number...
3
by: Mike Charney | last post by:
I have a two part question: First I want to insert data into a table and I am using the following command: INSERT INTO tblmain SELECT field1, field2, etc... FROM tblimport WHERE ?????? The...
3
by: rhaazy | last post by:
Using ms sql 2000 I have 2 tables. I have a table which has information regarding a computer scan. Each record in this table has a column called MAC which is the unique ID for each Scan. The...
1
by: Sockpuppet | last post by:
After having googles I've knocked together ther following code. What I am trying to do is select all items in one table and move through them adding them into other tables (splitting them and...
1
by: Wes Groleau | last post by:
INSERT INTO X ...... ( A, B, C ) INSERT INTO Y ...... ( J, K, L ) If Y has a foreign key M which is the primary key D of X, is there an easy and/or efficient way to have SQL Server assign D,...
6
by: cberthu | last post by:
Hi all, I have a strange (at least for me) things happening. I am save the result of an outer join into a file and I read this file and put these values into a table. The first row written...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
1
by: veasnamuch | last post by:
I have a problem while I create a trigger to my table. My objective is getting any change made to my table and record it in to another table . My have thousands records before I add new trigger to...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...

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.