我有两个查询可以找到我们数据库中所有受访者的邮政编码和州。他们来了
对于邮政编码:
select top 100  S.ID as SurveyID, S.SID, S.SurveyNumber, S.ABCSurveyName, SE.RespondentID, Q.name as QuestionName, rp.Condition as ZipCode
from Surveys S 
    join Sessions SE 
        on S.id = SE.SurveyID 
    join RespondentProfiles rp
        on RP.RespondentID = SE.RespondentID
    join Questions Q 
        on Q.ID = rp.QuestionID
where q.name = 'ZIP'
        and S.ID = 13900
        and Q.LK_RecordStatusID = 1
对于状态:
select VW.ID as SurveyID, VW.SID, SurveyNumber, ABCSurveyName, RespondentID, VW.Name as QuestionName, st.Code as State
from (
    select top 100 S.ID, S.SID, S.SurveyNumber, S.ABCSurveyName, SE.RespondentID, Q.name, rp.Condition 
    from Surveys S 
        join Sessions SE 
            on S.id = SE.SurveyID 
        join RespondentProfiles rp
            on RP.RespondentID = SE.RespondentID
        join Questions Q 
            on Q.ID = rp.QuestionID
    where S.ID = 13900
            and q.name = 'STATE'
            and Q.LK_RecordStatusID = 1
) VW
    join LK_States st
        on st.ID = vw.Condition
这可行,但我想将它们全部放在一张表中,即邮政编码和州。
谢谢!
问题架构:
Column_name 类型 计算长度 Prec Scale Nullable
TrimTrailingBlanks  FixedLenNullInSource    Collation
ID  int no  4   10      0       no  (n/a)   (n/a)   NULL
SID nvarchar    no  128                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
Name    nvarchar    no  64                  yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
QuestionIdentifier  nvarchar    no  128                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
ParentID    int no  4   10      0       yes (n/a)   (n/a)   NULL
LK_QuestionTypeID   int no  4   10      0       yes (n/a)   (n/a)   NULL
LK_QuestionCategoryID   int no  4   10      0       yes (n/a)   (n/a)   NULL
LK_IndustryID   int no  4   10      0       yes (n/a)   (n/a)   NULL
OptionMask  nvarchar    no  512                 yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
MetaTags    ntext   no  16                  yes (n/a)   (n/a)   SQL_Latin1_General_CP1_CI_AS
Order   int no  4   10      0       yes (n/a)   (n/a)   NULL
Rows    int no  4   10      0       yes (n/a)   (n/a)   NULL
Columns int no  4   10      0       yes (n/a)   (n/a)   NULL
IsDisplay   bit no  1                   yes (n/a)   (n/a)   NULL
AnswerLifespan  int no  4   10      0       yes (n/a)   (n/a)   NULL
CreateUserID    int no  4   10      0       yes (n/a)   (n/a)   NULL
CreateDate  datetime    no  8                   yes (n/a)   (n/a)   NULL
UpdateUserID    int no  4   10      0       yes (n/a)   (n/a)   NULL
UpdateDate  datetime    no  8                   yes (n/a)   (n/a)   NULL
LK_RecordStatusID   bit no  1                   yes (n/a)   (n/a)   NULL
LK_QuestionClassID  int no  4   10      0       yes (n/a)   (n/a)   NULL
LK_QuestionVisibilityID int no  4   10      0       yes (n/a)   (n/a)   NULL
DisplayLK_QuestionTypeID    int no  4   10      0       yes (n/a)   (n/a)   NULL