Sql查询一个表中除了某个字段以外的所有字段的方法

declare @name varchar(100)
declare @sql varchar(1000)


SET @sql='select '
DECLARE C11 CURSOR FOR

select name from syscolumns where id=
(select max(id) from sysobjects where xtype='u' and name='Album')//Album为表名
and name <> 'AlbumID'//AlbumID为要除去的表字段
OPEN C11

FETCH NEXT FROM C11 INTO
@name
IF @@FETCH_STATUS <> 0
BEGIN
DEALLOCATE C11
RETURN
END
WHILE(@@FETCH_STATUS = 0)
BEGIN
SET @sql=@sql+@name+','

FETCH NEXT FROM C11 INTO
@name
END
DEALLOCATE C11

set @sql=substring(@sql,1,len(@sql)-1)+' from Album'//Album为表名

exec (@sql)

图片如下:

posted @ 2011-11-08 15:50  Mygirl  阅读(4295)  评论(0编辑  收藏  举报