September 1, 2008 at 5:29 am
Hello,
I have a problem detailed below, that I need some help with.
Data for Person 1 is stored in Table 1 across multiple rows like this. (All values are character datatypes).
Person name age height
1 John NULL NULL
1 NULL 30 NULL
1 NULL NULL 192
I would like to use a SELECT statement to retrive the data on a single row.
Person name age height
1 John 30 192
I am sorry if this has been answered elsewhere I have seen similar questions posted but the examples given do not make much sense to me. Thanks in advance!
September 1, 2008 at 5:47 am
Hi There,
Try this:
DECLARE @Table TABLE
(Person VARCHAR(2),
name VARCHAR(10),
age VARCHAR(3),
height VARCHAR(3))
INSERT INTO @TABLE
SELECT '1', 'John', NULL, NULL UNION ALL
SELECT '1', NULL, '30', NULL UNION ALL
SELECT '1', NULL, NULL ,'192'
SELECT *
FROM @TABLE
SELECT
MAX(Person),
MIN(Name),
MIN(Age),
MIN(Height)
FROM @TABLE
GROUP BY PERSON
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
September 1, 2008 at 6:27 am
Is there any reason for storing data in this manner in the table?
September 1, 2008 at 6:55 pm
rosh (9/1/2008)
Is there any reason for storing data in this manner in the table?
Heh... yep... someone doesn't have a good split function or didn't know how to do a crosstab on an EAV... 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply