Solved

SQL Merge Rows

Posted on 2013-11-26
1
235 Views
Last Modified: 2013-11-26
Hello,
How can merge this table?

region  osType  MyPC    Cap
EMEA    Mac     NULL    1006
EMEA    Vista   NULL    811
EMEA    Vista   28      NULL
EMEA    Win2k   NULL    1
EMEA    Win7    NULL    3957
EMEA    Win7    177     NULL
EMEA    Win8    NULL    625
EMEA    Win8    16      NULL
EMEA    Win8.1  NULL    173
EMEA    Win8.1  15      NULL
EMEA    XP      NULL    981
EMEA    XP      30      NULL
NA      Mac     NULL    8493
NA      Vista   NULL    5965
NA      Vista   135     NULL
NA      Win2k   NULL    19
NA      Win7    NULL    32636
NA      Win7    631     NULL
NA      Win8    NULL    7790
NA      Win8    154     NULL
NA      Win8.1  NULL    1073
NA      Win8.1  33      NULL
NA      XP      NULL    8118
NA      XP      136     NULL
 
Need it to look like this

region  osType  MyPC    Cap
EMEA    Mac     NULL    1006
EMEA    Vista   28    811
EMEA    Win2k   NULL    1
EMEA    Win7         177    3957
EMEA    Win8    16    625
EMEA    Win8.1  15    173
EMEA    XP      30    981
NA      Mac     NULL    8493
NA      Vista   135    5965
NA      Win2k   NULL    19
NA      Win7    631   32636
NA      Win8    154    7790
NA      Win8.1  33    1073
NA      XP      136    8118

Here's my work in progress

Select * from
(select s1.region, s1.osType, s1.MyPC, s1.Cap
from @tmpTable0 as s1
inner join @tmpTable0 as s2
on s1.region = s2.region and s1.osType = s2.osType) t where t.myPC is not null and t.Cap is not null
0
Comment
Question by:Mauro Cazabonnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
Mauro Cazabonnet earned 0 total points
ID: 39677845
I got it

Select * from
(select s1.region, s1.osType, s1.MyPC, s2.Cap
from @tmpTable0 as s1
inner join @tmpTable0 as s2
on s1.region = s2.region and s1.osType = s2.osType) t where t.myPC is not null and t.Cap is not null
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL trigger 5 50
Enabled trace flag 4135 or 4199 - SQL SERVER 2 34
Why is this SQL bringing back extra rows? (parsing XML data) 4 66
Creating a View from a CTE 15 48
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question