Solved

SQL Merge Rows

Posted on 2013-11-26
1
218 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:mcazabonnet
1 Comment
 
LVL 4

Accepted Solution

by:
mcazabonnet 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now