查询的活动结果不包含任何字段 laravel
Posted
技术标签:
【中文标题】查询的活动结果不包含任何字段 laravel【英文标题】:The active result for the query contains no fields laravel 【发布时间】:2017-10-24 11:21:54 【问题描述】:我尝试使用参数执行存储过程,然后出现错误。
SQLSTATE[IMSSP]:查询的活动结果不包含任何字段。 (SQL: exec [dbo].[CHECK_ACCESS_ALL_EMP] '10249', '','','','','','')
但是我尝试在出错时执行选择结果
exec [dbo].[CHECK_ACCESS_ALL_EMP] '10249', '','','','','','' 工作正常 在数据库中,执行存储过程后的结果是:
SELECT EMPCODE, ALLNAME, SEX, DIVISION, DEPARTMENT AS DEPT, POSTDESC, EMAIL,CONVERT(VARCHAR, DOB, 106) AS DOB, TRANNO, LEVELCODE FROM RPT_EMPLOYEE
WHERE (TERMINATESTATUS='' OR (TERMINATESTATUS<>'' AND DATETERMINATE>=GETDATE()))
Laravel 函数
public function emplyeeList()
$employee = HREmpMast::orderBy('EMPCODE')->paginate(10);
$emp_code = Auth::user()->EMPCODE;
if($emp_code != null)
$script = DB::select("exec [dbo].[CHECK_ACCESS_ALL_EMP] '".$emp_code."', '','','','','',''");
return $script;
存储过程
USE [SOFITELSR_HRMS]
GO
/****** Object: StoredProcedure [dbo].[CHECK_ACCESS_ALL_EMP] Script Date: 10/24/2017 3:41:46 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CHECK_ACCESS_ALL_EMP](@EMPCODE VARCHAR(10),
@FILTER_EMPCODE VARCHAR(10),
@FILTER_EMPNAME VARCHAR(200),
@FILTER_CATEGOYR VARCHAR(10),
@FILTER_DIVISION VARCHAR(10),
@FILTER_DEPT VARCHAR(10),
@FILTER_POSITION VARCHAR(10)
)AS
BEGIN
DECLARE @ACCESS_ALL_EMP INT=0,@LINEID INT,@LINEID_DELEGATE INT,@DELCODE VARCHAR(10),
@VIEW_BY_DEPT VARCHAR(500),@VIEW_BY_DEPT_DELEGATE VARCHAR(500),@MYSCRIPT VARCHAR(1000)
SET @DELCODE=''
SET @VIEW_BY_DEPT=''
SET @MYSCRIPT='SELECT EMPCODE, ALLNAME, SEX, DIVISION, DEPARTMENT AS DEPT, POSTDESC, EMAIL,CONVERT(VARCHAR, DOB, 106) AS DOB, TRANNO, LEVELCODE FROM RPT_EMPLOYEE
WHERE (TERMINATESTATUS='''' OR (TERMINATESTATUS<>'''' AND DATETERMINATE>=GETDATE()))'
SELECT @DELCODE=EMPCODE FROM HR_LEAVEDELEGATE WHERE DELCODE=@EMPCODE--Get delegate information
SELECT @LINEID_DELEGATE=TRANNO FROM HR_EMPMAST WHERE EMPCODE=@DELCODE --Get line transaction no of delegate person
SELECT @LINEID=TRANNO FROM HR_EMPMAST WHERE EMPCODE=@EMPCODE--Get line transaction no
IF EXISTS(SELECT GDCODE FROM SYS_SETTING WHERE GDCODE=@EMPCODE) OR --General Manager
EXISTS(SELECT EMPCODE FROM HR_EMPMAST WHERE EMPCODE=@EMPCODE AND BOARD=1) OR --Operation Manager
EXISTS(SELECT HDCODE FROM SYS_SETTING WHERE HDCODE=@EMPCODE) OR --Head of HR
EXISTS(SELECT HRCODE FROM SYS_SETTING WHERE HRCODE=@EMPCODE) OR --HR Assistant
EXISTS(SELECT GDCODE FROM SYS_SETTING WHERE GDCODE=@DELCODE) OR --General Manager by delegate
EXISTS(SELECT EMPCODE FROM HR_EMPMAST WHERE EMPCODE=@DELCODE AND BOARD=1) OR --Operation Manager by delegate
EXISTS(SELECT HDCODE FROM SYS_SETTING WHERE HDCODE=@DELCODE) OR --Head of HR by delegate
EXISTS(SELECT HRCODE FROM SYS_SETTING WHERE HRCODE=@DELCODE) --HR Assistant by delegate
BEGIN
SET @ACCESS_ALL_EMP=1--THIS EMPLOYEE, ALLOW TO ACCESS ALL OF EMPLOYEES
PRINT 'VIEW ALL'
END
ELSE
BEGIN
PRINT 'VIEW BY ROLES'
--EMPLOYEE CONDITION
SET @MYSCRIPT+= ' AND (HODCODE=' + CAST(@LINEID AS VARCHAR(10))
IF @LINEID_DELEGATE>0
SET @MYSCRIPT+= ' OR HODCODE=' + CAST(@LINEID_DELEGATE AS VARCHAR(10))
IF EXISTS(SELECT CODE FROM HR_DEPARTMENT WHERE DM1=@EMPCODE OR DM2=@EMPCODE OR DM3=@EMPCODE)--IF HEAD OF DEPARTMENTS
BEGIN
EXEC GET_VIEW_BY_DEPT @EMPCODE,@VIEW_BY_DEPT OUTPUT
SET @MYSCRIPT+= ' OR DEPT IN (' + @VIEW_BY_DEPT + ')'
END
IF EXISTS(SELECT CODE FROM HR_DEPARTMENT WHERE (@DELCODE<>'' AND @DELCODE IS NOT NULL) AND (DM1=@DELCODE OR DM2=@DELCODE OR DM3=@DELCODE))--IF HEAD OF DEPARTMENTS DELEGATE USER
BEGIN
EXEC GET_VIEW_BY_DEPT @EMPCODE,@VIEW_BY_DEPT_DELEGATE OUTPUT
SET @MYSCRIPT+= ' OR DEPT IN (' + @VIEW_BY_DEPT_DELEGATE + ')'
END
SET @MYSCRIPT+=')'
END
-----USER FILES
IF @FILTER_EMPCODE<>'' AND @FILTER_EMPCODE IS NOT NULL--employee code
SET @MYSCRIPT+= ' AND EMPCODE LIKE ''%' + @FILTER_EMPCODE + '%'''
IF @FILTER_EMPNAME<>'' AND @FILTER_EMPNAME IS NOT NULL--employee name
SET @MYSCRIPT+= ' AND ALLNAME LIKE ''%' + @FILTER_EMPCODE + '%'''
PRINT @MYSCRIPT
END
【问题讨论】:
【参考方案1】:您正在调用 SQL 函数,而不是 SELECT。 而不是:
$script = DB::select("exec [dbo].[CHECK_ACCESS_ALL_EMP] '".$emp_code."', '','','','','',''");
试试:
$script = DB::raw("exec [dbo].[CHECK_ACCESS_ALL_EMP] '".$emp_code."', '','','','','',''");
【讨论】:
但是我从变量脚本中得到的结果是这样的: exec [dbo].[CHECK_ACCESS_ALL_EMP] '10249', '','','','','','' it不是预期的结果。【参考方案2】:问题在于 - 这个查询返回两个结果集 [旧的 mssql 引擎可能只是忽略了整个查询字符串中除了最后一个查询之外的所有查询]。
DB::select('SET NOCOUNT ON ; EXEC stored_procedure ... ')
使用SET NOCOUNT ON;
【讨论】:
【参考方案3】:正确的命令是:
$script = DB::update("exec [dbo].[CHECK_ACCESS_ALL_EMP] '".$emp_code."', '','','','','',''");
【讨论】:
以上是关于查询的活动结果不包含任何字段 laravel的主要内容,如果未能解决你的问题,请参考以下文章
Microsoft Access 2010 查询不产生任何结果