0% found this document useful (0 votes)
14 views

Cross Apply 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Cross Apply 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

CREATE TABLE dbo.

Struc
(
ID int NOT NULL
, Person nvarchar(30) NOT NULL
, Age int NOT NULL
, Gender char(1) NOT NULL
, Month1 int NOT NULL
, Value1 int NOT NULL
, Month2 int NOT NULL
, Value2 int NOT NULL
);

INSERT INTO dbo.Struc (ID, Person, Age, Gender, Month1, Value1, Month2, Value2)
VALUES (1, 'Jane', 20, 'F', 201507, 1, 201508, 0)
, (2, 'John', 30, 'M', 201507, 0, 201508, 1);

SELECT s.ID
, s.Person
, s.Age
, s.Gender
, v.Month
, v.Value
FROM dbo.Struc s
CROSS APPLY (VALUES
(Month1, Value1)
, (Month2, Value2)
) v(Month, Value);

You might also like