比如
SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC
SELECT name2 FROM web_Admin2 WHERE ID=1 ORDER BY ID DESC
SELECT name3 FROM web_Admin3 WHERE ID=1 ORDER BY ID DESC
SELECT name4 FROM web_Admin4 WHERE ID=1 ORDER BY ID DESC
SELECT name5 FROM web_Admin5 WHERE ID=1 ORDER BY ID DESC
SELECT name6 FROM web_Admin6 WHERE ID=1 ORDER BY ID DESC如何在存储过程中获取这个数据?@name1=SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC??
SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC
SELECT name2 FROM web_Admin2 WHERE ID=1 ORDER BY ID DESC
SELECT name3 FROM web_Admin3 WHERE ID=1 ORDER BY ID DESC
SELECT name4 FROM web_Admin4 WHERE ID=1 ORDER BY ID DESC
SELECT name5 FROM web_Admin5 WHERE ID=1 ORDER BY ID DESC
SELECT name6 FROM web_Admin6 WHERE ID=1 ORDER BY ID DESC如何在存储过程中获取这个数据?@name1=SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC??
union all
SELECT name2 FROM web_Admin2 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name3 FROM web_Admin3 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name4 FROM web_Admin4 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name5 FROM web_Admin5 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name6 FROM web_Admin6 WHERE ID=1 ORDER BY ID DESC
as
SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name2 FROM web_Admin2 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name3 FROM web_Admin3 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name4 FROM web_Admin4 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name5 FROM web_Admin5 WHERE ID=1 ORDER BY ID DESC
union all
SELECT name6 FROM web_Admin6 WHERE ID=1 ORDER BY ID DESC
还是没听明白~~
@name1=SELECT name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC
修改为
SELECT @name1 = name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC
但要注意,你必须保证返回的记录只有1行,不然,要抱错,所以为了解决这个问题,加上TOP1,就不管它返回多少行了SELECT TOP 1 @name1 = name1 FROM web_Admin1 WHERE ID=1 ORDER BY ID DESC