Hi,
Suppose I have a table like this:
IF OBJECT_ID('dbo.Soils', 'U') IS NOT NULL
DROP TABLE dbo.Soils;
CREATE TABLE Soils(
CHKEY varchar (5) NULL,
LAYER1 int NULL,
A1 decimal (4, 1) NULL,
B1 decimal (4, 1) NULL
);
INSERT INTO dbo.Soils(CHKEY, LAYER1, A1, B1)
VALUES ('a', 1, 6.1, 2.3), ('a', 2, 5.1, 2.3), ('a', 3, 8.1, 3.2), ('a', 4, 6.4, 2.0),
('b', 1, 2, 1), ('b', 2, 2.1, 5.1),
('c', 1, 3.2, 12.0), ('c', 2, 8.1, 7.1), ('c', 3., 10.5, 6.0);
SELECT * FROM Soils;
The above creates a table like this:
CHKEY | LAYER1 | A1 | B1 |
a | 1 | 6.1 | 2.3 |
a | 2 | 5.1 | 2.3 |
a | 3 | 8.1 | 3.2 |
a | 4 | 6.4 | 2 |
b | 1 | 2 | 1 |
b | 2 | 2.1 | 5.1 |
c | 1 | 3.2 | 12 |
c | 2 | 8.1 | 7.1 |
c | 3 | 10.5 | 6 |
How do I create a T-SQL query to get the following output:
CHKEY LAYER1 A1 B1 LAYER2 A2 B2 LAYER3 A3 B3 LAYER4 A4
B4
a 1 6.1 2.3 2 5.1 2.3
3 8.1 3.2 4 6.4 2
b 1 2 1 2 2.1 5.1
c 1 3.2 12 2 8.1 7.1
3 10.5 6
Appreciate any help.
Marilyn Gambone