以下简单的存储过程无法返回结果集,即使单独运行这个简单的 SELECT 语句与实际值也可以正常工作。任何想法为什么?
ALTER PROCEDURE [dbo].[PageHeadingGetText]
@PageType nvarchar(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT @PageType FROM [dbo].[PageHeadingText]
END
以下简单的存储过程无法返回结果集,即使单独运行这个简单的 SELECT 语句与实际值也可以正常工作。任何想法为什么?
ALTER PROCEDURE [dbo].[PageHeadingGetText]
@PageType nvarchar(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT @PageType FROM [dbo].[PageHeadingText]
END
You didn't ask directly but in the title you say "Setting the field selection of a SELECT". You have to use dynamic SQL to dynamically build a statement :
ALTER PROCEDURE [dbo].[PageHeadingGetText]
@columns nvarchar(max)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sqlCommand NVARCHAR(MAX)
SET @sqlCommand = 'SELECT ' + @columns + ' FROM [dbo].[PageHeadingText]'
EXECUTE sp_executesql @sqlCommand
END