日期:2014-05-18 浏览次数:20697 次
[code=SQL]
DECLARE @表的前n个字段 int,@ColList varchar(200) SET @表的前n个字段=5 SELECT @ColList=ISNULL(@ColList+',','')+QUOTENAME(name) FROM syscolumns WHERE id=OBJECT_ID('dbo.Employees') and colid<=@表的前n个字段 EXEC('SELECT '+@ColList+' FROM dbo.Employees') /* EmployeeID LastName FirstName Title TitleOfCourtesy ----------- -------------------- ---------- ------------------------------ ------------------------- 1 Davolio Nancy Sales Representative Ms. 2 Fuller Andrew Vice President, Sales Dr. 3 Leverling Janet Sales Representative Ms. 4 Peacock Margaret Sales Representative Mrs. 5 Buchanan Steven Sales Manager Mr. 6 Suyama Michael Sales Representative Mr. 7 King Robert Sales Representative Mr. 8 Callahan Laura Inside Sales Coordinator Ms. 9 Dodsworth Anne Sales Representative Ms. (9 行受影响) */