存储过程返回整数而不是ISingleResult

时间:2011-06-03 07:17:21

标签: .net linq-to-sql

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中返回两个数据表。但是当我在dbml中拖放这个SP时,它的返回类型变为int而不是Isingleresult。如何解决这个问题。

3 个答案:

答案 0 :(得分:1)

我也有这个问题,这肯定是由临时表引起的。我修复它的方法是添加

SET FMTONLY OFF;

到存储过程的开头。该解决方案取自this blog,其中讨论了实体框架,但同样适用于Linq to Sql。

答案 1 :(得分:0)

过去我遇到过类似的问题。我认为它在SP中有临时表。我不记得究竟是如何解决它的,但我认为它与使用用户定义的函数而不是存储过程有关。

使用Linq-to-Sql而不是SP?

是否无法实现此目的?

答案 2 :(得分:0)

以这种方式DECLARE @TempTable TABLE而不是CREATE TABLE #tempActualDates声明你的临时表,你会很高兴。