com.microsoft.sqlserver.jdbc.SQLServerException:不明确的列名' Incident_id'

时间:2015-06-10 06:30:55

标签: sql-server

以下存储过程会出现以下错误

  

com.microsoft.sqlserver.jdbc.SQLServerException:不明确的列名' Incident_id'

USE [FusionSysLive]
GO
/****** Object:  StoredProcedure [dbo].[RCPT_Search_Reports]    Script ****/       
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER PROCEDURE [dbo].[RCPT_Search_Reports]  
@pagesize int = 10, 
@pagestart int= 0, 
@querysrting varchar(20) = '', 
@orderBy varchar(40)= '',
@incident_id numeric(9) =null,
@searchdate varchar(20) =null ,
@search_string varchar(40) =null ,  
@action_type varchar(40) =null ,
@security_grp_id numeric(10),
@company_id numeric(10) 

as
set nocount on
set quoted_identifier off

CREATE TABLE #Temp (
    Row numeric(10, 0) ,
    Incident_id numeric(10, 0) null,
    Description varchar(50),
    Creation_timestamp varchar(100) null,
)

set nocount on
set quoted_identifier off

declare @query varchar(max)

set @query = 'select ROW_NUMBER() OVER (order by '+@orderBy +') AS      Row,inc.Incident_id, inc.Description, inc.Creation_timestamp from Incident     inc, Incident_list incl  where inc.Incident_id = incl.Incident_id '

If(@security_grp_id = 1)
Begin
Set @query =  @query + 'and  (inc.Company_id ='+cast(@company_id as       varchar)+' or inc.Company_id is null) '
End
Else
Begin
Set @query =  @query + 'and  inc.Company_id ='+cast(@company_id as     varchar) 
End
If ( ( @incident_id<>0 and @incident_id is not null) or ( (@action_type =     'byGroupID' or @action_type = 'byGroupName' ) and   @incident_id=0 and      @search_string=''  and @searchdate=''  ))
Begin
    Set @query =  @query + ' and inc.Incident_id='  + cast(@incident_id   as varchar)
End

If (@action_type is not null and @search_string is not null and     @action_type!='' and @search_string!='' )
Begin
If (@action_type = 'byGroupID')
Begin
    Set @query =  @query + ' and incl.Recipient_list_id  in  (select Group_id from Contact_group where Group_id like '''+ @search_string + '%'') '
End
Else If (@action_type = 'byGroupName')
Begin
    Set @query =  @query + ' and incl.Recipient_list_id in (select     Group_id from Contact_group where Group_name like '''+ @search_string + '%'')    '
End
End

If (@searchdate is not null and @searchdate!='' )
Begin
Set @query = @query +  ' and CONVERT(datetime, FLOOR(CONVERT(float(24),    Creation_timestamp))) =''' + @searchdate + ''''
End

set @query = @query + ' order by inc.Incident_id';

print @query
insert into #Temp exec(@query)

select row ,Incident_id , Description , Creation_timestamp
from #Temp where Row > @pagestart and row <= (@pagestart + @pagesize)

select count(*) as total_count from #Temp 

 drop table #Temp

0 个答案:

没有答案