鍍金池/ 問答/數(shù)據(jù)庫(kù)/ SQL 求助: 遍歷一個(gè)存了 table 名和 column 名的表,驗(yàn)證是否匹

SQL 求助: 遍歷一個(gè)存了 table 名和 column 名的表,驗(yàn)證是否匹配某個(gè)值

假設(shè)表格 Summary 如下:

TableName ColName Desc
t1 c1 blah blah
t2 c2 blah blah
t3 c3 blah blah

求哪位大神給指導(dǎo)下,怎么寫一個(gè) stored procedure, 傳進(jìn)一個(gè) int 參數(shù),然后返回是否有某個(gè) TableName 里的 ColName 的值與它匹配?

例:
傳進(jìn) 2, 遍歷 t1 表格里的 c1, t2 表格里的 c2, t3 表格里的 c3,看看是否有一個(gè)的值為 2

主要是這里怎么遍歷這個(gè) Summary 表,并且獲得 TableName 中 ColName 的值來與傳進(jìn)的參數(shù)相比較

回答
編輯回答
心悲涼
select c1 as res from t1 where c1=2
union
select c2 as res from t2 where c2=2
union
select c3 as res from t3 where c3=2
....
2018年6月25日 23:45