2011-06-03 45 views
1
ALTER PROCEDURE [dbo].[VCT_SP_SUBJECT_EMAIL_REMINDER] 
AS 
CREATE TABLE #tempEstimatedDates(
SUBJECT_ID int, 
FIRST_NAME varchar(200), 
LAST_NAME varchar(200), 
MIDDLE_NAME varchar(200), 
EMAIL_ID varchar(200), 
ACTIVITY_VALUE datetime, 
SUB_VISIT_ID int, 
VISIT_NO INT, 
VISIT_DETAIL_ID INT, 
PROTOCOL_ID INT, 
LOCATION_ID INT, 
SITE_ID INT, 
SITE_NAME VARCHAR(200), 
PROTOCOL_NAME VARCHAR(200) 
) 
INSERT INTO 

#tempEstimatedDates(SUBJECT_ID,FIRST_NAME,LAST_NAME,MIDDLE_NAME,EMAIL_ID,  
ACTIVITY_VALUE, 
SUB_VISIT_ID,VISIT_NO,VISIT_DETAIL_ID,PROTOCOL_ID  
,LOCATION_ID,PROTOCOL_NAME,SITE_ID,SITE_NAME) 
SELECT * FROM dbo.[GET_SUBJECT_SCHEDULE]('Estimated Date Of Next Visit') 

---TABLE FOR ACTUAL DATE OF VISIT--- 
CREATE TABLE #tempActualDates(
SUBJECT_ID int, 
FIRST_NAME varchar(200), 
LAST_NAME varchar(200), 
MIDDLE_NAME varchar(200), 
EMAIL_ID varchar(200), 
ACTIVITY_VALUE datetime, 
SUB_VISIT_ID int, 
VISIT_NO INT, 
VISIT_DETAIL_ID INT, 
PROTOCOL_ID INT, 
LOCATION_ID INT, 
SITE_ID INT, 
SITE_NAME VARCHAR(200), 
PROTOCOL_NAME VARCHAR(200) 
) 
INSERT INTO 

#tempActualDates(SUBJECT_ID,FIRST_NAME,LAST_NAME,MIDDLE_NAME,EMAIL_ID, 
ACTIVITY_VALUE,SUB_VISIT_ID, 
VISIT_NO,VISIT_DETAIL_ID,PROTOCOL_ID ,LOCATION_ID,PROTOCOL_NAME,SITE_ID,SITE_NAME) 
SELECT * from dbo.[GET_SUBJECT_SCHEDULE]('Actual Date Of Visit') 
select * from #tempEstimatedDates 
where subject_id in 
(select subject_id from #tempActualDates) and visit_no not in (select visit_NO from 
#tempActualDates) 
AND 
( convert(varchar,ACTIVITY_VALUE,101)=convert(varchar,getdate(),101) 
or dateadd(d,2,convert(varchar,getdate() 
,101))=convert(varchar,ACTIVITY_VALUE,101) 
or dateadd(d,1,convert(varchar,getdate() ,101))=convert(varchar,ACTIVITY_VALUE,101) 
) 
UNION 
select * from #tempEstimatedDates 
where subject_id NOT in 
(select subject_id from #tempActualDates) 
AND 
( convert(varchar,ACTIVITY_VALUE,101)=convert(varchar,getdate(),101) 
or dateadd(d,2,convert(varchar,getdate() 
,101))=convert(varchar,ACTIVITY_VALUE,101) 
or dateadd(d,1,convert(varchar,getdate() ,101))=convert(varchar,ACTIVITY_VALUE,101) 
) 
select * from #tempEstimatedDates 
where subject_id in 
(select subject_id from #tempActualDates) and visit_no not in (select visit_NO from 
#tempActualDates) 
AND 
( --convert(varchar,ACTIVITY_VALUE,101)=convert(varchar,getdate(),101) or 
DATEDIFF(d,convert(varchar,ACTIVITY_VALUE,101),convert(varchar,getdate() 
,101))=2  
or DATEDIFF(d,convert(varchar,ACTIVITY_VALUE,101),convert(varchar,getdate() 
,101))=1  
) 
UNION 
select * from #tempEstimatedDates 
where subject_id NOT in 
(select subject_id from #tempActualDates) 
AND 
( --convert(varchar,ACTIVITY_VALUE,101)=convert(varchar,getdate(),101) OR 
DATEDIFF(d,convert(varchar,ACTIVITY_VALUE,101),convert(varchar,getdate() 
,101))=2 
or DATEDIFF(d,convert(varchar,ACTIVITY_VALUE,101),convert(varchar,getdate() 
,101))=1  
) 
drop table #tempEstimatedDates 
drop table #tempActualDates 

這是我的存儲過程,它在sql server中返回兩個數據表。但是,當我拖放這個SP在dbml中,它的返回類型變成了int而不是Isingleresult。如何解決這個問題呢。返回整數而不是ISingleResult的存儲過程

回答

0

我以前有過類似的問題。我認爲它在SP中有臨時表。我不記得我是如何解決它的,但我認爲它與使用用戶定義的函數而不是存儲的proc有關。

是否有沒有辦法使用Linq-to-Sql而不是SP來實現這一點?

+0

請給我一些想法,比如如何爲此製作UDF – 2011-06-03 08:00:11

+0

對不起,我真的不記得了。你應該能夠谷歌如何創建UDF的。一旦你創建了它,你就可以將它添加到你的.dbml文件中,就像你使用SP一樣。 – simonlchilds 2011-06-06 08:55:17

0

用這種方式聲明你的臨時表DECLARE @TempTable TABLE而不是CREATE TABLE #tempActualDates,你會很開心。

1

我有這個問題,以及這是肯定的臨時表引起的。我修復它的方法是將

SET FMTONLY OFF; 

添加到存儲過程的開始。該解決方案取自this blog,它討論了實體框架,但似乎也適用於Linq to Sql。

+0

謝謝!不知道爲什麼,但這個救了我! – 2014-03-18 23:06:41