我正在尝试运行一个过程,在该过程中我将发送表名以从中获取所有记录..这样我就不必创建不同的过程...但是我在这方面遇到了一些问题。
ALTER PROCEDURE [dbo].[getTableData]
-- Add the parameters for the stored procedure here
@tableName Varchar(100),
@whrFldName NVarchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @ActualTableName AS NVarchar(255)
SELECT @ActualTableName = QUOTENAME( TABLE_NAME )
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = @tableName
DECLARE @sql AS NVARCHAR(MAX)
SELECT @sql = 'SELECT * FROM ' + @ActualTableName + ' WHERE ' +
@whrFldName + ' = ''y'' ;'
--PRINT @sql
EXEC(@SQL)
END
PHP代码是这样的..
$sql ="EXEC [dbo].[getTableData] 'tbl_services','serviceStatus'";
$rst = odbc_exec($connection, $sql);
$i = 0;
while($result = odbc_fetch_array($rst))
{
$returnPageData[$i] = $result;
$i++;
}
它在服务器中执行得很好,但是当我从我的PHP代码中调用它时,它返回 null。
在这里,如果我删除并放置字段它工作正常..我已经很好地测试了我的代码,它特别为文本*
类型字段创建了问题..
如果我将程序更改为此,它工作正常..
ALTER PROCEDURE [dbo].[getTableData]
-- Add the parameters for the stored procedure here
@rowsPerPage as bigint,
@pageNum as bigint
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
WITH SQLPaging AS (
SELECT TOP(@rowsPerPage * @pageNum) ROW_NUMBER() OVER (ORDER BY creationDate DESC)
AS resultNum, *
FROM [DB_SB].[dbo].[tbl_blog] )
SELECT
blogTitle,
blogSlug,
blogImage,
substring( blogContent, 1, 210 ) AS blogContent,
creationDate,
blogAddedBy
FROM SQLPaging WITH (nolock) WHERE resultNum > ((@pageNum - 1) * @rowsPerPage)
结尾
但这不合逻辑..如果我每次都发送字段..这不是我想要的..
任何解决方案?请帮助...