日期:2014-05-17 浏览次数:20519 次
ALTER PROC [dbo].[dfn_fjck_getpid] @rectype VARCHAR(20) , ---------------------传说中的a @main_sid VARCHAR(20) ---------------------传说中的b AS BEGIN DECLARE @tablename VARCHAR(100) DECLARE @projectid VARCHAR(20) DECLARE @keyfield VARCHAR(20) DECLARE @sql VARCHAR(1000) SELECT @tableName = tableName , @keyfield = keyField , @projectid = projectidField FROM pub_SelfDefine WHERE rectype = @rectype --将结果插入临时表 SET @sql = ' SELECT ' +@keyfield +','+ @main_sid +','+@projectid + ' ----------------传说中的c FROM ' + @tablename + 'into #temp WHERE ' + @keyfield + ' = ''' + @main_sid + ''' ' PRINT @sql EXEC( @sql) --临时表关联视图得到c select a.a,a.b,b.c from 视图A a inner join #temp b on a.a=b.a and a.b=b.b END
------解决方案--------------------
哈哈,你想写个动态sql 拼sql串好了