SSMS - How to convert multiple rows for a client into fields for a column
up vote
0
down vote
favorite
This is my first question, so apologies if I am missing any etiquette.
I have a SSMS qry which pulls together 3 databases from 2 servers. all working ok, but I have been asked to add another field which surprise surprise is in a different table.
The problem I am having, is that this new table has multiple rows for a client, so as an example. I Have in my data, Policy Number, Driver Name, Car, Reg.
I am joining the new table via policy number, but the new table has additional drivers, so for each additional driver there is a new row (so a row with the same policy number for each add driver). I want 1 field from this new table ("relationship to Driver") to be shown in columns on the main table I have. So add driver 1, add driver 2 etc, there is a field in each row which identifies if the row is first, second, third driver etc.
Is this something anyone can help with at all?
Thanks
sql join ssms
add a comment |
up vote
0
down vote
favorite
This is my first question, so apologies if I am missing any etiquette.
I have a SSMS qry which pulls together 3 databases from 2 servers. all working ok, but I have been asked to add another field which surprise surprise is in a different table.
The problem I am having, is that this new table has multiple rows for a client, so as an example. I Have in my data, Policy Number, Driver Name, Car, Reg.
I am joining the new table via policy number, but the new table has additional drivers, so for each additional driver there is a new row (so a row with the same policy number for each add driver). I want 1 field from this new table ("relationship to Driver") to be shown in columns on the main table I have. So add driver 1, add driver 2 etc, there is a field in each row which identifies if the row is first, second, third driver etc.
Is this something anyone can help with at all?
Thanks
sql join ssms
Please provide the database scheme and some sample data.
– mypetlion
Nov 7 at 17:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is my first question, so apologies if I am missing any etiquette.
I have a SSMS qry which pulls together 3 databases from 2 servers. all working ok, but I have been asked to add another field which surprise surprise is in a different table.
The problem I am having, is that this new table has multiple rows for a client, so as an example. I Have in my data, Policy Number, Driver Name, Car, Reg.
I am joining the new table via policy number, but the new table has additional drivers, so for each additional driver there is a new row (so a row with the same policy number for each add driver). I want 1 field from this new table ("relationship to Driver") to be shown in columns on the main table I have. So add driver 1, add driver 2 etc, there is a field in each row which identifies if the row is first, second, third driver etc.
Is this something anyone can help with at all?
Thanks
sql join ssms
This is my first question, so apologies if I am missing any etiquette.
I have a SSMS qry which pulls together 3 databases from 2 servers. all working ok, but I have been asked to add another field which surprise surprise is in a different table.
The problem I am having, is that this new table has multiple rows for a client, so as an example. I Have in my data, Policy Number, Driver Name, Car, Reg.
I am joining the new table via policy number, but the new table has additional drivers, so for each additional driver there is a new row (so a row with the same policy number for each add driver). I want 1 field from this new table ("relationship to Driver") to be shown in columns on the main table I have. So add driver 1, add driver 2 etc, there is a field in each row which identifies if the row is first, second, third driver etc.
Is this something anyone can help with at all?
Thanks
sql join ssms
sql join ssms
edited Nov 7 at 19:37
jarlh
27.9k52137
27.9k52137
asked Nov 7 at 17:01
Aimone111
1
1
Please provide the database scheme and some sample data.
– mypetlion
Nov 7 at 17:13
add a comment |
Please provide the database scheme and some sample data.
– mypetlion
Nov 7 at 17:13
Please provide the database scheme and some sample data.
– mypetlion
Nov 7 at 17:13
Please provide the database scheme and some sample data.
– mypetlion
Nov 7 at 17:13
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194292%2fssms-how-to-convert-multiple-rows-for-a-client-into-fields-for-a-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please provide the database scheme and some sample data.
– mypetlion
Nov 7 at 17:13