选择所有列数据为上
目前我正在使用upper(columnname) as 'xyz'
这是失去名字,我不想要
我的要求是select col1,col2,col3,col4 from xyz table
我正在寻找一种方法,可以在单一语法中将所有4个col设置为更高,而不会丢失列名
例如:select Upper(col1,col2,col3,col4) from xyz table
答案 0 :(得分:0)
试试这个
DECLARE @columnName varchar(25)
DECLARE @cursor CURSOR
declare @sql nvarchar(1000)
declare @tableName as nvarchar(30)
set @tableName = 'YOURTABLE'
SET @cursor = CURSOR FOR
select c.name from sys.columns c inner join sys.tables t on c.object_id = t.object_id
where c.object_id = (select object_id from sys.tables where name = @tableName )
OPEN @cursor
FETCH NEXT
FROM @cursor INTO @columnName
WHILE @@FETCH_STATUS = 0
BEGIN
set @sql = 'update YOURTABLE set '+ @columnName +' = upper(' + @columnName + ') where YOURTABLE.'+@columnName+' = YOURTABLE.'+ @columnName+''
EXEC(@sql)
FETCH NEXT
FROM @cursor INTO @columnName
END
CLOSE @cursor
DEALLOCATE @cursor
更新:您必须更新所有列,以便所有列都变为大写
注意: 请在进行之前备份您的餐桌 将YOURTABLE更改为您的表名
答案 1 :(得分:-1)
试试这个:
select UPPER(col1) AS Col1,UPPER(col2) AS col2,UPPER(col3) as
col3,UPPER(col4 ) as col4 from xyz table