我收到一个未知的返回类型错误当我将存储过程添加到我的dbml中时。下面是我的Sp。我无法弄清楚错误。我已经检查了太多与之相关的问题,并且解决方案是不使用临时表。我没有使用临时表,而是使用某些博客建议的表变量,但后来我也收到错误。请帮忙。
ALTER PROCEDURE dbo.Reports
(
@startDate datetime,
@endDate datetime,
@pageType int,
@assignedClincian int
)
AS
BEGIN
Declare @SqlQuery varchar(max)
Declare @strCondition varchar(max)
Declare @tempTable Table
(
First_Name varchar(150),
Last_Name varchar(150),
ID int,
PageType_Id int,
Rf_Date datetime,
DOB datetime,
InsuranceCompany varchar(250),
AssignedClincian varchar(250)
)
set @SqlQuery = 'select * from tblusers'
If @startDate IS NOT NULL AND @endDate is Not null
Begin
set @strCondition = ' FO.Rf_Date >= convert(datetime, ''' + Convert(varchar,@startDate,112) + ''') and FO.Rf_Date<= convert(datetime, ''' + Convert(varchar,@endDate,112) + ''')'
End
Else if @startDate IS NOT NULL
Begin
set @strCondition = ' FO.Rf_Date >=' + @startDate
End
Else if @EndDate IS NOT NULL
Begin
set @strCondition = ' FO.Rf_Date <=' + @EndDate
End
if @pageType > 0
Begin
set @strCondition = (case when @strCondition='' then '' else @strCondition + ' and ' end) + ' FO.PageType_Id='+ Convert(varchar,@pageType)
End
if @assignedClincian > 0
Begin
set @strCondition = (case when @strCondition='' then '' else @strCondition + ' and ' end) +' p1.AST_Clinician_Assginments_To=' + Convert(varchar,@assignedClincian)
End
set @SqlQuery=(case when @strCondition='' then @SqlQuery else @SqlQuery + ' where ' + @strCondition end) + ' order by Fo.ID'
insert into @tempTable EXEC (@SqlQuery)
select * from @tempTable
END
RETURN
答案 0 :(得分:0)
所以,在一团糟之后,我结束了一个解决方案,在第二个其他条件下,我没有像第一个条件那样正确地转换日期:
Else if @startDate IS NOT NULL
Begin
set @strCondition = ' FO.Rf_Date >=' + @startDate
End