Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Update Column by "aggregating" text from another table column

$
0
0

Hi,

SUPPOSE I HAVE THESE 2 TABLES:

IF OBJECT_ID('dbo.HUC824K', 'U') IS NOT NULL
 DROP TABLE dbo.HUC824K;

CREATE TABLE dbo.HUC824K(
  FIPS_C [varchar] (254) NULL,
  HUC8 [varchar] (8) NULL);
 
INSERT INTO dbo.HUC824K(FIPS_C, HUC8)
VALUES
('01010002', '23003 23021 23025'),
('01010003', '23003'),
('01010004', '23003 23019 23021');

IF OBJECT_ID('dbo.NETBLUE', 'U') IS NOT NULL
 DROP TABLE dbo.NETBLUE;

CREATE TABLE dbo.NETBLUE(
  FIPS [varchar] (50) NULL,
  HUC8 [varchar] (8) NULL);

INSERT INTO dbo.NETBLUE(FIPS, HUC8)
VALUES
('23003', NULL),
('23021', NULL),
('23025', NULL),
('23019', NULL);

What is the correct query that would result in HUC8 values for NetBlue table as follows:

FIPS         HUC8
'23003'    '01010002 01010003 01010004'  --space-delimited
'23019'    '01010004'
'23021'    '01010002 01010004'
'23025'    '01010002'

Appreciate your assistance.


Marilyn Gambone


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>