带参数的存储过程动态创建一个视图及调用方法[表不固定,作为参数]

SQL Server中执行带参数的存储过程的方法是: EXEC 存储过程名字 ‘参数1′,’参数2′,数值参数 如 Exec sp_configure 'OldOwner','dbo',1 实例:存储过程动态创建一个视图[表不固定,作为参数] CREATE proc p_test @tablename varchar(255) as exec('if object_id(''EveryDay'',''v'') is not null drop view EveryDay') exec('CREATE VIEW dbo.EveryDay AS SELECT '+@TableName+' .*, dbo.BSInfo.CellNameCN, dbo.BSInfo.SiteNoName FROM dbo.BSInfo INNER JOIN '+@TableName+' ON dbo.BSInfo.CellName = '+@TableName+' .CELL_NAME') GO SQL查询分析器中调用方法:exec p_test 'table_20110317'

你可能感兴趣的:(JOIN,sql,server,object,null,table,存储)