Query Help
-
Hello, I have the following query working well, however; I need to augment it and what seemed simple has really stumoed me. Maybe some of you can guide me in the right direction. use db1 select distinct v.userid, v.firstname, v.lastname, c.[name] as 'credential field', q.address, value from import3 inner join vulture v on v.userid = external inner join credentialfielddef c on c.id = fieldid inner join vulture_commo o on o.vultureid = v.id inner join Commo q on q.id = o.vultureid where q.commotypeid like '4' order by userid Results look like this: UserId Firstname Lastname Crednetial Field Value GUID Jim Roberts Field1 Test1 GUID Jim Roberts Field2 Test2 GUID Jim Roberts Field3 Test3 GUID Jim Roberts Field4 Test4 Desired Result set: UserId Firstname Lastname Field1 Field2 field3 field4 GUID Jim Roberts Test1 Test2 Test3 Test4 The schema is nightmare and it took me a while just to get where I am now but I am stuck and need a little insight as to the best approach. I have tried using varibles and considered case statements but I am truely lost. Any help would be appreciated on the best method.
Regards, Hulicat
-
Hello, I have the following query working well, however; I need to augment it and what seemed simple has really stumoed me. Maybe some of you can guide me in the right direction. use db1 select distinct v.userid, v.firstname, v.lastname, c.[name] as 'credential field', q.address, value from import3 inner join vulture v on v.userid = external inner join credentialfielddef c on c.id = fieldid inner join vulture_commo o on o.vultureid = v.id inner join Commo q on q.id = o.vultureid where q.commotypeid like '4' order by userid Results look like this: UserId Firstname Lastname Crednetial Field Value GUID Jim Roberts Field1 Test1 GUID Jim Roberts Field2 Test2 GUID Jim Roberts Field3 Test3 GUID Jim Roberts Field4 Test4 Desired Result set: UserId Firstname Lastname Field1 Field2 field3 field4 GUID Jim Roberts Test1 Test2 Test3 Test4 The schema is nightmare and it took me a while just to get where I am now but I am stuck and need a little insight as to the best approach. I have tried using varibles and considered case statements but I am truely lost. Any help would be appreciated on the best method.
Regards, Hulicat
-
How are stored your data on table, can you post here data on your table?
I Love T-SQL "Don't torture yourself,let the life to do it for you."
-
I was able to accomplish the desired result via CASE statements. Thanks, Dennis
Regards, Hulicat