Showing posts with label field2. Show all posts
Showing posts with label field2. Show all posts

Thursday, March 8, 2012

copy data from 2 tables

I need to copy the data in the last name table to the field2 table do i use the update query in sql 2005?I don't really know enough about your problem to answer your question. Depending on the table structure and the tools you are using the answer is probably either yes or no.

I'm going to move your question to the SQL Server forum, since that is the database engine that you're using. See the FAQ at the top of the forum postings for the entry on how to ask questions to get quick and correct answers, it should help a lot.

I'll be happy to help, once I know what your tables look like, and what client tool(s) you are using (Query Analyzer, Microsoft Access, etc).

-PatP|||I have two databases database1 and database2 i need to copy all the data in database1 field lastname to database2 field field2 but only if database1.cust_no matches database2.sourceid|||CREATE TABLE database1 (
cust_no VARCHAR(9)
, lastname VARCHAR(25)
)

CREATE TABLE database2 (
cust_no VARCHAR(9)
, field2 VARCHAR(100)
)

INSERT INTO database1 (cust_no, lastname)
SELECT 'doe', 'Doe' UNION
SELECT 'jones', 'Jones' UNION
SELECT 'freshfitz', 'Freshfitz' UNION
SELECT 'pope', 'Pope' UNION
SELECT 'smith', 'Smith'

INSERT INTO database2 (cust_no, field2)
SELECT 'doe', NULL UNION
SELECT 'jones', 'Jones' UNION
SELECT 'freshfitz', 'was here' UNION
SELECT 'popper', NULL UNION
SELECT 'smith', 'Smith'

UPDATE z
SET field2 = lastname
FROM database2 AS z
JOIN database1 AS x
ON (x.cust_no = z.cust_no)

SELECT *
FROM database2

DROP TABLE database1
DROP TABLE database2-PatP|||Thats awesome but the problem is database1 and database 2 already exist and the fields already exist i just need to copy all the records in the field of database 1 field last name to database2 field field2(which has no data). The records in database1 have a unique id Cust_no that match the same unique id in database2 sourceid.

So if cust_no = sourceid copy the last name field

select * from database1 field lastname
copy to database2 field field2
where database1.cust_no = database2_sourceid|||So just start with the UPDATE, and you'll be fine.

-PatP

Sunday, February 19, 2012

Converting to crosstab table

Hello there
I have table with 2 fields: table1(Field1, Field2)
I need to present it as crosstab in this way:
Original:
1, 1
2, 2
2, 3
3, 4
3, 5
3, 6
3, 7
Should look like this:
1, 1
2, 2, 3
3, 4, 5, 6
4, 7
How can i do this dinamicly?See if this helps.
http://groups.google.com/group/micr...br />
6dd9e73e
AMB
"Roy Goldhammer" wrote:

> Hello there
> I have table with 2 fields: table1(Field1, Field2)
> I need to present it as crosstab in this way:
> Original:
> 1, 1
> 2, 2
> 2, 3
> 3, 4
> 3, 5
> 3, 6
> 3, 7
> Should look like this:
> 1, 1
> 2, 2, 3
> 3, 4, 5, 6
> 4, 7
> How can i do this dinamicly?
>
>|||Can you explain the logic behind the result?
--
"Roy Goldhammer" wrote:

> Hello there
> I have table with 2 fields: table1(Field1, Field2)
> I need to present it as crosstab in this way:
> Original:
> 1, 1
> 2, 2
> 2, 3
> 3, 4
> 3, 5
> 3, 6
> 3, 7
> Should look like this:
> 1, 1
> 2, 2, 3
> 3, 4, 5, 6
> 4, 7
> How can i do this dinamicly?
>
>|||I think he had a typo in his sample data.
Roy, this is why producing something we can repro will cause less problems.
Please generate CREATE TABLE and INSERT statements instead of typing out
tabular data by hand, it will be much less prone to errors. See
http://www.aspfaq.com/5006
"Omnibuzz" <Omnibuzz@.discussions.microsoft.com> wrote in message
news:A4DFEBEC-BABA-4929-9821-3077466EFA2F@.microsoft.com...
> Can you explain the logic behind the result?
> --
>
>
> "Roy Goldhammer" wrote:
>|||We don't need your ddl statements to confirm that whatever
type of dynamic xtab you want you can do easily with Rac:)
www.rac4sql.net