Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
slserra
Starting Member
19 Posts |
Posted - 2003-10-05 : 13:35:12
|
| I have the following tables:tbl_ResponseLayoutFieldId Title------- ------------ 1 Name 2 Address 3 Phonetbl_ResponsesRespId FieldId FieldValue------ ------- ---------- 1 1 Steve 1 2 1 Main St 1 3 555-1212 2 2 100 Center StI'm having trouble creating a query that returns all three layout fields for each response. If a response exists for the particular field show the response otherwise return a null value. The output table would look like this:RespId FieldId FieldValue------ ------- ---------- 1 1 Steve 1 2 1 Main St 1 3 555-1212 2 1 NULL 2 2 100 Center St. 2 3 NULLHow can this be done in SQL?Thanks for you help.Steve |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-10-05 : 14:47:59
|
| select r.RespId, l.FieldId, r2.FieldValuefrom tbl_ResponseLayout lcross join (select distinct RespId from tbl_Responses) rleft outer join tbl_Responses r2on r2.respId = r.respIdand r2.fieldId = l.fieldIdorder by r.RespId, l.FieldId==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
slserra
Starting Member
19 Posts |
Posted - 2003-10-05 : 17:48:41
|
| Thanks! This is exactly what I needed.Steve |
 |
|
|
|
|
|