2016-02-19 225 views
0

我有一個從臨時表構建的報表,它將即時報表放入SSRS報表中。我的報告運行良好,直到我嘗試從SSRS報告中運行它。將varchar值「 - 」轉換爲日期類型時轉換失敗INT

錯誤即時得到是

轉換轉換VARCHAR值時失敗「 - 」最新型INT

我對這個報告,其中運行良好其他臨時表,有每個迷你SQL只有1個額外的條件。

------TOTAL DATA ALLOCATED X0------ 

create table #DATAIMPORTEDX1SS 
(
[AGENT] varchar(32) 
,[Allocated x1] int 
) 

insert into #DATAIMPORTEDX1SS 
([AGENT],[Allocated x1]) 

Select ui.username [AGENT], count(DISTINCT(ah.accountid)) as [Allocated x1] 
From [sysdba].[DCLALLOCHIST] ah 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
INNER JOIN [sysdba].[DCLACCELECMPAN] EM ON EM.ACCOUNTID = AH.ACCOUNTID 
--INNER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = AH.ACCOUNTID 
Where ah.source = 'Scar' 
and ah.timesout = 1 
and ah.createdate >= @startdate AND ah.createdate <= @enddate 
and ui.username <> 'Loren Portwood' 
group by ui.username 
order by 1 

------Quoted Elec------ 

create table #QUOTEDELECSS1 
(
    [AGENT] varchar(32) 
    ,[QUOTED ELEC] int 
) 

insert into #QUOTEDELECSS1 
([AGENT],[QUOTED ELEC]) 


Select [AGENT], Count(distinct(id)) as Count 
from 
(
SELECT DiSTINCT 
ROW_NUMBER() OVER (PARTITION BY E.ACCOUNTID Order by E.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, E.ACCOUNTID AS ID, ui.username [AGENT], AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCELEC] E ON E.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
AND H.DESCRIPTION IN ('Renewal Quote - Elec: Confirm MPAN','Renewal Quote - Elec and Gas: Confirm MPAN and MPR') 
AND A.ACCOUNTID NOT IN 
(
SELECT A.ACCOUNTID 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCELECMPAN] EM ON EM.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND H.DESCRIPTION = 'Renewal Quote - Elec: Confirm Price' 
) 
UNION ALL 
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY EM.MPANBOTTOM Order by EM.MPANBOTTOM) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, EM.DCLACCELECMPANID AS ID, ui.username [AGENT],AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCELECMPAN] EM ON EM.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
AND H.DESCRIPTION = 'Renewal Quote - Elec: Confirm Price' 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [AGENT] 

------Quoted Gas------ 


create table #QUOTEDGASSS1 
(
    [AGENT] varchar(32) 
    ,[QUOTED_GAS] int 
) 

insert into #QUOTEDGASSS1 
([AGENT],[QUOTED_GAS]) 


Select [AGENT], Count(distinct(id)) as Count 
from 
(
SELECT DiSTINCT 
ROW_NUMBER() OVER (PARTITION BY E.ACCOUNTID Order by E.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, E.ACCOUNTID AS ID, ui.username [AGENT], AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCgas] E ON E.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
AND H.DESCRIPTION IN ('Renewal Quote - Gas: Confirm MPR','Renewal Quote - Elec and Gas: Confirm MPAN and MPR') 
AND A.ACCOUNTID NOT IN 
(
SELECT A.ACCOUNTID 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCgasmpr] EM ON EM.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND H.DESCRIPTION = 'Renewal Quote - Gas: Confirm Price' 
) 
UNION ALL 
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY EM.MPRSERIAL Order by EM.MPRSERIAL) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, EM.MPRSERIAL AS ID, ui.username [AGENT],AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCgasmpr] EM ON EM.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
AND H.DESCRIPTION = 'Renewal Quote - Gas: Confirm Price' 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [AGENT] 


------GOOD ELEC------ 


create table #GOODELECSS1 
(
    [AGENT] varchar(32) 
    ,[GOOD_ELEC] int 
) 

insert into #GOODELECSS1 
([AGENT],[GOOD_ELEC]) 

Select [USERNAME], Count(DCLACCELECMPANID) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY em.MPANBOTTOM Order by em.MPANBOTTOM) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, EM.DCLACCELECMPANID, ui.username as [USERNAME], a.account, em.MPANBOTTOM,AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCELECMPAN] EM ON EM.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
AND H.DESCRIPTION = 'Renewal Quote - Elec: Confirm Price' 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 

------GOOD GAS------ 


create table #GOODGASSS1 
(
    [AGENT] varchar(32) 
    ,[GOOD_GAS] int 
) 

insert into #GOODGASSS1 
([AGENT],[GOOD_GAS]) 

Select [USERNAME], Count(DCLACCGASMPRID) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY GM.MPRSERIAL Order by GM.MPRSERIAL) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, GM.DCLACCGASMPRID, ui.username as [USERNAME],AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
FROM ACCOUNT A 
LEFT OUTER JOIN SYSDBA.HISTORY H ON H.ACCOUNTID = A.ACCOUNTID 
LEFT OUTER JOIN [sysdba].[DCLACCGASMPR] GM ON GM.ACCOUNTID = A.ACCOUNTID 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
WHERE LEADSOURCEID = 'L6UJ9A00009H' 
and A.CREATEDATE >= @startdate and A.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
AND H.DESCRIPTION = 'Renewal Quote - Gas: Confirm Price' 
) X where X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 


------LOA SUBMITTED ELEC------ 


create table #LOAELECSUBSS1 
(
    [AGENT] varchar(32) 
    ,[LOA_SUBE] int 
) 

insert into #LOAELECSUBSS1 
([AGENT],[LOA_SUBE]) 

Select [USERNAME], Count(accountid) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY A.ACCOUNTID Order by A.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, A.ACCOUNTID, UI.USERNAME AS [USERNAME], a.account,AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
from SLXLive.sysdba.dclaccelec g 
inner join [sysdba].[HISTORY] h on h.accountid = g.accountid 
inner join [sysdba].[account] a on a.accountid = g.accountid 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
--where quotestage = 'LOA Submitted' 
where h.description in ('LOA - Elec: LOA Submitted') 
and a.leadsourceid = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
and ah.source = 'Scar' 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 

------LOA SUBMITTED GAS------ 


create table #LOAGASSUBSS1 
(
    [AGENT] varchar(32) 
    ,[LOA_SUBG] int 
) 

insert into #LOAGASSUBSS1 
([AGENT],[LOA_SUBG]) 

Select [USERNAME], Count(accountid) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY A.ACCOUNTID Order by A.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, A.ACCOUNTID, UI.USERNAME AS [USERNAME],AH.TIMESOUT [Timesout], h.createdate [Quotedate],Ah.CREATEDATE [allocdate] 
from SLXLive.sysdba.dclaccgas g 
inner join [sysdba].[HISTORY] h on h.accountid = g.accountid 
inner join [sysdba].[account] a on a.accountid = g.accountid 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
--where quotestage = 'LOA Submitted' 
where h.description in ('LOA - Gas: LOA Submitted') 
and a.leadsourceid = 'L6UJ9A00009H' 
and Ah.CREATEDATE >= @startdate and Ah.CREATEDATE <= @enddate 
AND (h.createdate>Ah.CREATEDATE) 
and ah.source = 'Scar' 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 

------AWAITING CED ELEC------ 


create table #AWAITCEDELECSS1 
(
    [AGENT] varchar(32) 
    ,[AWCED_ELEC] int 
) 

insert into #AWAITCEDELECSS1 
([AGENT],[AWCED_ELEC]) 

Select [USERNAME], Count(accountid) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY A.ACCOUNTID Order by A.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, A.ACCOUNTID, UI.USERNAME AS [USERNAME],AH.TIMESOUT [Timesout], e.quotestagedate [Await_Date], Ah.CREATEDATE [allocdate] 
From SLXLive.sysdba.Account a 
Inner Join SLXLive.sysdba.dclaccelec e on a.accountid = e.accountid 
Left Outer Join SLXLive.sysdba.dclaccelecmpan m on e.accountid = m.accountid 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
Where a.leadsourceid = 'L6UJ9A00009H' 
and AH.CREATEDATE >= @startdate and AH.CREATEDATE <= @enddate 
AND (e.quotestagedate >Ah.CREATEDATE) 
and ah.timesout = 0 
and Quotestage = 'Awaiting CED' and m.signed_date is null 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 

------AWAITING CED GAS------ 


create table #AWAITCEDGASSS1 
(
    [AGENT] varchar(32) 
    ,[AWCED_GAS] int 
) 

insert into #AWAITCEDGASSS1 
([AGENT],[AWCED_GAS]) 

Select [USERNAME], Count(accountid) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY A.ACCOUNTID Order by A.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, A.ACCOUNTID, UI.USERNAME AS [USERNAME],AH.TIMESOUT [Timesout], e.quotestagedate [Await_Date], Ah.CREATEDATE [allocdate] 
From SLXLive.sysdba.Account a 
Inner Join SLXLive.sysdba.dclaccgas e on a.accountid = e.accountid 
Left Outer Join SLXLive.sysdba.dclaccgasmpr m on e.accountid = m.accountid 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
Where a.leadsourceid = 'L6UJ9A00009H' 
and AH.CREATEDATE >= @startdate and AH.CREATEDATE <= @enddate 
AND (e.quotestagedate >Ah.CREATEDATE) 
and Quotestage = 'Awaiting CED' and m.signed_date is null 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 

------SIGNED ELEC------ 

create table #ELECSIGNEDSS1 
(
    [AGENT] varchar(32) 
    ,[SIGNED_ELEC] int 
) 

insert into #ELECSIGNEDSS1 
([AGENT],[SIGNED_ELEC]) 

Select [USERNAME], Count(accountid) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY A.ACCOUNTID Order by A.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, A.ACCOUNTID, UI.USERNAME AS [USERNAME],AH.TIMESOUT [Timesout], m.signed_date [Signed_Date], Ah.CREATEDATE [allocdate] 
From SLXLive.sysdba.Account a 
Inner Join SLXLive.sysdba.dclaccelec e on a.accountid = e.accountid 
Left Outer Join SLXLive.sysdba.dclaccelecmpan m on e.accountid = m.accountid 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
Where a.leadsourceid = 'L6UJ9A00009H' 
AND AH.CREATEDATE >= @Startdate and AH.CREATEDATE <= @enddate 
AND (m.signed_date >Ah.CREATEDATE) 
and m.signed_date is not null 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 

------SIGNED GAS------ 

create table #GASSIGNEDSS1 
(
    [AGENT] varchar(32) 
    ,[SIGNED_GAS] int 
) 

insert into #GASSIGNEDSS1 
([AGENT],[SIGNED_GAS]) 

Select [USERNAME], Count(accountid) as Count 
from 
(
SELECT DISTINCT 
ROW_NUMBER() OVER (PARTITION BY A.ACCOUNTID Order by A.ACCOUNTID) ROWNUM, 
CASE WHEN A.LEADSOURCEID = 'L6UJ9A00009H' THEN 'Scarlet Sheep' 
    Else A.LEADSOURCEID END AS Leadsource, A.ACCOUNTID, UI.USERNAME AS [USERNAME],AH.TIMESOUT [Timesout], m.signed_date [Signed_Date], Ah.CREATEDATE [allocdate] 
From SLXLive.sysdba.Account a 
Inner Join SLXLive.sysdba.dclaccelec e on a.accountid = e.accountid 
Left Outer Join SLXLive.sysdba.dclaccgasmpr m on e.accountid = m.accountid 
inner join [sysdba].[DCLALLOCHIST] ah on a.accountid = ah.accountid 
inner join [sysdba].[USERINFO] ui ON ah.userid = ui.userid 
Where a.leadsourceid = 'L6UJ9A00009H' 
AND AH.CREATEDATE >= @Startdate and AH.CREATEDATE <= @enddate 
AND (m.signed_date >Ah.CREATEDATE) 
and m.signed_date is not null 
) X WHERE X.ROWNUM = 1 AND X.timesout = 1 
Group by [USERNAME] 





-------------------------------------------------- 
------------Master Table-------------------------- 
-------------------------------------------------- 

create table #SCARLETTRESULTS1 
(
    [AGENT] varchar(32) 
    ,[Allocated x1] int 
    ,[QUOTED ELEC] int 
    ,[QUOTED_GAS] int 
    ,[GOOD_ELEC] int 
    ,[GOOD_GAS] int 
    ,[LOA_SUBE] int 
    ,[LOA_SUBG] int 
    ,[AWCED_ELEC] int 
    ,[AWCED_GAS] int 
    ,[SIGNED_ELEC] int 
    ,[SIGNED_GAS] int 
) 

insert into #SCARLETTRESULTS1 
     ([AGENT],[Allocated x1],[QUOTED ELEC],[QUOTED_GAS],[GOOD_ELEC],[GOOD_GAS],[LOA_SUBE],[LOA_SUBG],[AWCED_ELEC],[AWCED_GAS],[SIGNED_ELEC],[SIGNED_GAS]) 

SELECT #DATAIMPORTEDX1SS.[AGENT], #DATAIMPORTEDX1SS.[Allocated x1], #QUOTEDELECSS1.[QUOTED ELEC], #QUOTEDGASSS1.[QUOTED_GAS], #GOODELECSS1.[GOOD_ELEC], #GOODGASSS1.[GOOD_GAS], #LOAELECSUBSS1.[LOA_SUBE], 
     #LOAGASSUBSS1.[LOA_SUBG], #AWAITCEDELECSS1.[AWCED_ELEC], #AWAITCEDGASSS1.[AWCED_GAS], #ELECSIGNEDSS1.[SIGNED_ELEC], #GASSIGNEDSS1.[SIGNED_GAS] 
FROM #DATAIMPORTEDX1SS 
     LEFT JOIN #QUOTEDELECSS1 ON #QUOTEDELECSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #QUOTEDGASSS1 ON #QUOTEDGASSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #GOODELECSS1  ON #GOODELECSS1.[AGENT]  = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #GOODGASSS1  ON #GOODGASSS1.[AGENT]  = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #LOAELECSUBSS1 ON #LOAELECSUBSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #LOAGASSUBSS1 ON #LOAGASSUBSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #AWAITCEDELECSS1 ON #AWAITCEDELECSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #AWAITCEDGASSS1 ON #AWAITCEDGASSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #ELECSIGNEDSS1 ON #ELECSIGNEDSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 
     LEFT JOIN #GASSIGNEDSS1 ON #GASSIGNEDSS1.[AGENT] = #DATAIMPORTEDX1SS.[AGENT] 


--DROP TABLE #DATAIMPORTEDX1SS 
--DROP TABLE #QUOTEDELECSS1 
--DROP TABLE #QUOTEDGASSS1 
--DROP TABLE #GOODELECSS1 
--DROP TABLE #GOODGASSS1 
--DROP TABLE #LOAELECSUBSS1 
--DROP TABLE #LOAGASSUBSS1 
--DROP TABLE #AWAITCEDELECSS1 
--DROP TABLE #AWAITCEDGASSS1 
--DROP TABLE #ELECSIGNEDSS1 
--DROP TABLE #GASSIGNEDSS1 
--DROP TABLE #SCARLETTRESULTS1 

select isnull([AGENT],0) AS [AGENT], isnull([Allocated x1],0) AS [Allocated x1], isnull([QUOTED ELEC],0) AS [QUOTED ELEC], isnull([QUOTED_GAS],0) AS [QUOTED_GAS], isnull([GOOD_ELEC],0) AS [GOOD_ELEC] 
, isnull([GOOD_GAS],0) AS [GOOD_GAS], isnull([LOA_SUBE],0) AS [LOA_SUBE], isnull([LOA_SUBG],0) AS [LOA_SUBG], isnull([AWCED_ELEC],0) AS [AWCED_ELEC], isnull([AWCED_GAS],0) AS [AWCED_GAS] 
, isnull([SIGNED_ELEC],0) AS [SIGNED_ELEC], isnull([SIGNED_GAS],0) AS [SIGNED_GAS] 
from #SCARLETTRESULTS1 

如果任何人都可以點我的方向是正確的歡呼聲

+0

對我來說確實看起來像SQL Server,所以我刪除了MySQL標籤。 –

+1

哇,這是很多代碼。你有什麼想法,你認爲這個問題在哪裏?你能把它縮小一點,還是把它分解成更多可消化的塊? – MathBio

+0

管理層希望報告顯示proc的方式相當矮胖。 –

回答

1

你有表#DATAIMPORTEDX1SS。對於任何想要轉換爲數字的字符字段,請使用兩列。第一個將是一個varchar列,您將使用它來接收來自任何的數據。另一個將是整數,浮動,無論你需要什麼。然後執行以下操作:

update #DATAIMPORTEDX1SS 
set theNumericField = cast(theVarcharField as integer) 
where isNumeric(theVarcharField) = 1 

在報告中使用NumericField。

+0

工作感謝。 –

+0

此代碼整理了我的報告,但現在失敗了,我無法工作。請你能解釋2列嗎? –

相關問題