USE [InformationSystem] GO /****** Object: StoredProcedure [dbo].[pro_oper] Script Date: 05/06/2015 16:07:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <把执行的结果赋给变量> -- ============================================= ALTER PROCEDURE [dbo].[pro_oper] AS DECLARE @strSql NVARCHAR(max) DECLARE @term_code NVARCHAR(100) SET @strSql='' set @strSql='SELECT top 1 @a=term_code FROM jingpai_line.dbo.st_product_plan where 1=1 and line_code=102 and status=2' --PRINT @strSql BEGIN TRY exec sp_executesql @strSql,N'@a varchar(100) output',@term_code output --把执行的结果赋给变量@term_code END TRY BEGIN CATCH RETURN -2 END CATCH print @term_code