SQL Row aggregation [duplicate]
This question already has an answer here:
Comma separated results in SQL
3 answers
Sample data:
Id User Value
1 A X=1
1 A Y=2
1 A X=1
1 A X=1
1 A Y=2
1 A X=1
1 A Y=2
1 A X=0
1 A NULL
1 A NULL
I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....
i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.
sql-server
marked as duplicate by Larnu, Martin Smith
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Comma separated results in SQL
3 answers
Sample data:
Id User Value
1 A X=1
1 A Y=2
1 A X=1
1 A X=1
1 A Y=2
1 A X=1
1 A Y=2
1 A X=0
1 A NULL
1 A NULL
I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....
i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.
sql-server
marked as duplicate by Larnu, Martin Smith
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Comma separated results in SQL
3 answers
Sample data:
Id User Value
1 A X=1
1 A Y=2
1 A X=1
1 A X=1
1 A Y=2
1 A X=1
1 A Y=2
1 A X=0
1 A NULL
1 A NULL
I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....
i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.
sql-server
This question already has an answer here:
Comma separated results in SQL
3 answers
Sample data:
Id User Value
1 A X=1
1 A Y=2
1 A X=1
1 A X=1
1 A Y=2
1 A X=1
1 A Y=2
1 A X=0
1 A NULL
1 A NULL
I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....
i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.
This question already has an answer here:
Comma separated results in SQL
3 answers
sql-server
sql-server
asked Nov 11 at 17:22
Srini
134
134
marked as duplicate by Larnu, Martin Smith
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Larnu, Martin Smith
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 17:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can do like
SELECT ID,
[User],
STUFF(
(
SELECT ' OR ' + '(' + Value + ')'
FROM T T2
WHERE T2.ID = T1.ID
FOR XML PATH('')
), 1, 4, ''
) Result
FROM T T1
GROUP BY ID, [User];
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do like
SELECT ID,
[User],
STUFF(
(
SELECT ' OR ' + '(' + Value + ')'
FROM T T2
WHERE T2.ID = T1.ID
FOR XML PATH('')
), 1, 4, ''
) Result
FROM T T1
GROUP BY ID, [User];
add a comment |
You can do like
SELECT ID,
[User],
STUFF(
(
SELECT ' OR ' + '(' + Value + ')'
FROM T T2
WHERE T2.ID = T1.ID
FOR XML PATH('')
), 1, 4, ''
) Result
FROM T T1
GROUP BY ID, [User];
add a comment |
You can do like
SELECT ID,
[User],
STUFF(
(
SELECT ' OR ' + '(' + Value + ')'
FROM T T2
WHERE T2.ID = T1.ID
FOR XML PATH('')
), 1, 4, ''
) Result
FROM T T1
GROUP BY ID, [User];
You can do like
SELECT ID,
[User],
STUFF(
(
SELECT ' OR ' + '(' + Value + ')'
FROM T T2
WHERE T2.ID = T1.ID
FOR XML PATH('')
), 1, 4, ''
) Result
FROM T T1
GROUP BY ID, [User];
answered Nov 11 at 17:38
Sami
7,32931039
7,32931039
add a comment |
add a comment |