SQL Query problem concat text field from mulitple rows into one text field 
Author Message
 SQL Query problem concat text field from mulitple rows into one text field
Does anybody know how to update a single text field in a
table from multiple rows in another table.

Thanks



Wed, 11 Feb 2004 01:12:00 GMT
 SQL Query problem concat text field from mulitple rows into one text field

If you mean "from multiple columns in another table" , sure,

Update TableX
    SET FieldSingleText= TableY.Field1+TableY.Field2
    FROM TableY
    Where TableX.PrimaryKeyField=TableY.PrimaryKeyField

NB If you're using mssql, issue
set concat_null_yields_null off
before you run it ,

hth
R.


Quote:
> Does anybody know how to update a single text field in a
> table from multiple rows in another table.

> Thanks



Wed, 11 Feb 2004 01:47:10 GMT
 SQL Query problem concat text field from mulitple rows into one text field

Thanks Rob,
However that is not my problem;
Here it is.
Table A;
ID   Desc
1    NULL
2    NULL
3    NULL

Table B;
ID   CODE
1    AS
1    SN
1    PT
2    SN
2    RN
3    AM
3    SN
3    RN
3    PT

I need table A updates to result in
ID   Desc
1    AS SN PT
2    SN RN
3    AM SN RN PT

Do you my problem now.... Any ideas you may have would be very helpful...

Thanks
AP

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 11 Feb 2004 02:11:47 GMT
 SQL Query problem concat text field from mulitple rows into one text field
There must be an elegant way of doing it--but I don't know what it is ;
This code won't run of course, just gives you an idea....

set concat_null_yields...

update tableA set desc=null


create cursor UA local forward_only read_only
for
select id, code from Table B
order by /* if it matters.... */

open UA



    begin

    fetch next ...
    end

close UA
deallocate ua

set concat ON
---

hth
Robert.

Update

Quote:

> Thanks Rob,
> However that is not my problem;
> Here it is.
> Table A;
> ID   Desc
> 1    NULL
> 2    NULL
> 3    NULL

> Table B;
> ID   CODE
> 1    AS
> 1    SN
> 1    PT
> 2    SN
> 2    RN
> 3    AM
> 3    SN
> 3    RN
> 3    PT

> I need table A updates to result in
> ID   Desc
> 1    AS SN PT
> 2    SN RN
> 3    AM SN RN PT

> Do you my problem now.... Any ideas you may have would be very helpful...

> Thanks
> AP

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Wed, 11 Feb 2004 02:26:17 GMT
 SQL Query problem concat text field from mulitple rows into one text field
This is great...Rob Thanks again...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 11 Feb 2004 03:04:15 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. Problem with updating from TEXT field into TEXT field

2. Concat mulitple rows from a table problem.

3. Copy text field from one row to another???

4. Text Field -> Repeating Calculation (Text) Field

5. Webpage won't show text field but will show calc of text field

6. extracting address text from one field into separate fields

7. Paradox merging two text fields into one one

8. Text justification problems with 4.1 on Windows (fields and text boxes)

9. PROBLEMS INSERTING MEMO FIELDS FROM TABLE FIELD TO TEXT FILE

10. loading a 400K text file into a text field in SQL

11. Saving Rich Text to sql server Text Fields

12. Update text pattern [0-9] with SQL Server text field


 
Powered by phpBB® Forum Software