USE [MyTestDb] GO /****** Object: StoredProcedure [dbo].[PROC_GetChannelList] Script Date: 04/09/2015 09:55:45 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <LH> -- Create date: <2015年4月9日 10:19:32> -- Description: <Test> -- ============================================= ALTER PROCEDURE [proc_findTable] @TableName VARCHAR(100), @TableColumn VARCHAR(MAX), @TableWhere VARCHAR(MAX) AS DECLARE @SQL VARCHAR(MAX) SET @SQL = 'SELECT '+@TableColumn+' FROM '+@TableName IF @TableWhere != '' BEGIN SET @SQL += ' WHERE 1=1 ' + @TableWhere END BEGIN EXEC(@SQL) END DECLARE @SQLWhere VARCHAR(100) SET @SQLWhere = '' exec [proc_findTable] 'MyTestTableOne','*',@SQLWhere