all groups > sql server programming > april 2007 >
You're in the

sql server programming

group:

insert question



insert question GotDotNet?
4/27/2007 3:39:46 PM
sql server programming: I have to do an insert on a table were 1 column needs to comes from tableA
other columns need to come from tableB.


so I have table A
Downloaded
Location

Table B
Name
Address
City
State
ZipCode

now the table I need to insert needs the following
Name
Address
City
state
ZipCode
Downloaded

i know I can do a insert into tableC (name, adderss, city, state, zipcode)
select (col1,col2,col3,col4,col4) from tableb

how can i get the download field in table A to insert into tableC?


Re: insert question GotDotNet?
4/27/2007 4:06:14 PM
how its designed to work is

the uses clicks a download button, that then inserts true or false and the
salespersons name in TableA, then its suppose to do the select from tableA
and tableB and insert them into TableC.






[quoted text, click to view]

Re: insert question GotDotNet?
4/27/2007 4:27:28 PM
OK, I just got a change

what it is now is an ID.(downloadID);

so i need to do something like this
1) generate this ID - guid:
2) select from tableb to insert into tableC and generate this downloadid


how would somethign like that be accomplished?

'insert into tablec (downloadID - needs to be a generated GUID, col2,col3)
select (col1,col2,col3) from tableb




[quoted text, click to view]

Re: insert question David Portas
4/27/2007 8:50:29 PM
[quoted text, click to view]

You have a set of values for Downloaded but you haven't explained how we are
to know which of those values goes with which address in TableB.

I'll assume you'll want a join on some criteria that you haven't specified.
Example:

INSERT INTO TableC (name, address, city, state, zipcode, downloaded)
SELECT B.name, B.address, B.city, B.state, B.zipcode, A.downloaded
FROM TableA AS A
INNER JOIN TableB AS B
ON A.something = B.something AND .... ??? ;

HTH

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--









Re: insert question David Portas
4/27/2007 10:49:59 PM
[quoted text, click to view]

A guess:

INSERT INTO TableC (downloadid, name, address, city, state, zipcode)
SELECT NEWID(), name, address, city, state, zipcode
FROM TableB AS B ;

For future reference, the best way to describe your problem is to post a
CREATE TABLE statement and a few rows of sample data (INSERT statements).
Always specify keys with your CREATE TABLE statements.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

AddThis Social Bookmark Button