2011-06-03 56 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