1

我一直在寻找答案,但发现自己更加困惑。我没有那么有经验 - 但员工人数很少 - 只有我创建报告 - 我必须创建这个。

客户要求提供一份报告,该报告将返回存储在 2 个数据库中的调查问题的 MTD 答案。问题是 - 他们想要附加到每个提交的答案的记录,而不是调查的一部分。即每个受访者都有关于他们拥有的电话类型、居住地区、电话型号和服务天数的信息。(虽然这些不是答案)

其中许多是独一无二的。(模型和城市)

例如,我在 SQL 中创建了一个存储过程来拉入 SSRS 以显示结果。

但每一个都是一个选择,我只得到第一个结果。我尝试添加UNION ALL,但是当我这样做时,它似乎并没有让我将它们分组。我将所有内容放在一列中,而我需要将它们放在单独的列中-理想情况下是水平的。但这可能要求太多了。

这是一个示例-也许有更快的方法-这是一个巨大的项目-我的截止日期现在快要到了-我已经尝试了很多东西-并且正在搜索。除了寻求帮助,别无他法。

所以这就是我所拥有的 -

ALTER PROCEDURE [dbo].[TEST_WIRELESS_DISCO_SURVEY_RESULTS]
(
   @STARTDATE DATETIME,
   @ENDDATE DATETIME
)
AS
BEGIN
   SELECT 
       a.CUSTOM17 as 'Make', COUNT(ISNULL(A.custom17, 0)) as 'Total Make'
   FROM GCI_SURVEYS as a
   JOIN GCI_Post_Survey_PreRepair_Master as b ON a.CustAcctNo = b.CustAcctNo
   WHERE b.Trans_Date between @STARTDATE and @ENDDATE
     AND a.i3_rowid = 'GCI_WRLSDISC_BSV'
     AND a.Q01 = 'no'
   GROUP BY  CUSTOM17

   UNION ALL

   SELECT 
       a.CUSTOM22 as 'Market', COUNT(ISNULL(a.CUSTOM22, 0)) as 'Total Market'
   FROM GCI_SURVEYS  as a
   JOIN GCI_Post_Survey_PreRepair_Master as b ON a.CustAcctNo = b.CustAcctNo
   WHERE b.Trans_Date between @STARTDATE  and @ENDDATE
     AND a.i3_rowid = 'GCI_WRLSDISC_BSV'
     AND a.Q01 = 'no'
   GROUP BY  a.CUSTOM22
4

2 回答 2

0

In the Question you stated that you are fetching data from two Database

return MTD answers on survey questions that are stored in 2 databases

In you SP you are Selecting from the same the DB

Just add the Database Name in one of your Select Query

于 2013-04-10T06:32:41.663 回答
0

根据您的解释,我认为工会的顶部和底部包含相同的调查,只是不同的部分?

我个人会将它们加载到变量表(或者如果有很多记录,临时表)中,然后将它们连接在一起。

DECLARE @MakeQuestion TABLE
(
  survery_id INT --datatype
 ,make       VARCHAR(200) --replace with your own
 ,total_make INT
)

INSERT INTO @MakeQuestion
SELECT a.join_condition, a.CUSTOM17 as 'Make',COUNT(ISNULL(A.custom17,0)) as 'Total Make'
FROM GCI_SURVEYS as a
JOIN GCI_Post_Survey_PreRepair_Master as b
ON a.CustAcctNo = b.CustAcctNo
WHERE b.Trans_Date between @STARTDATE and @ENDDATE
AND a.i3_rowid = 'GCI_WRLSDISC_BSV'
AND a.Q01 = 'no'
GROUP BY  a.join_condition,CUSTOM17

DECLARE @MarketQuestion TABLE
(
  survery_id  INT -- datatype
 ,market        VARCHAR(200) --replace with your own
 ,total_market INT
)

Insert INTO @MarketQuestion
SELECT  a.join_condition, a.CUSTOM22 as 'Market',COUNT(ISNULL(a.CUSTOM22,0)) as 'Total Market'
FROM GCI_SURVEYS  as a
JOIN GCI_Post_Survey_PreRepair_Master as b
ON a.CustAcctNo = b.CustAcctNo
WHERE b.Trans_Date between @STARTDATE  and @ENDDATE
AND a.i3_rowid = 'GCI_WRLSDISC_BSV'
AND a.Q01 = 'no'
GROUP BY  a.CUSTOM22

SELECT *
FROM @MakeQuestion Make
INNER JOIN @MarketQuestion Market ON Make.survey_id = Market.survery_id

如果我误解了,请告诉我。

于 2013-04-10T06:38:22.427 回答