将表中的所有数据都更改为大写的查询是什么? [英] What is the query to change all the datas to uppercase in a table?

查看:54
本文介绍了将表中的所有数据都更改为大写的查询是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有一个名为T1的表,其中有50列.

我需要编写一个查询,以使用单个查询将50列中的数据更改为大写.

满怀期待,
Viswanathan.M

Dear All,

I have a Table named as T1 which has 50 columns.

I need to write a query to change the datas in the 50 columns to uppercase by using a single query.

with expectation,
Viswanathan.M

推荐答案

类似的东西:
Something like:
UPDATE MyTable
   SET Col1 = UPPER(Col1),
       Col2 = UPPER(Col2), ....


SELECT 'UPDATE YOURTABLENAME SET ' + name + '=' + 'UPPER(' + name + ')'
FROM syscolumns
WHERE id = object_id('YOURTABLENAME')



这将创建一个查询,只需将其复制粘贴并运行即可.

注意:删除标识列(如果有).否则会引发错误.

希望对您有所帮助.



This will create a query just copy-paste it and run it.

NOTE : Remove identity column if any. Otherwise it will raise an error.

Hope it helps.


此查询可以做到.
This query will do it.
declare @sql        VARCHAR(8000)
declare @tableName  SYSNAME
set     @tableName  = ''yourTableNameGoesHere''

set     @sql = ''UPDATE '' + @tableName + '' SET '' + 
        (
        select  QUOTENAME(COLUMN_NAME) + '' = UPPER('' + QUOTENAME(COLUMN_NAME) + ''), ''
        from    INFORMATION_SCHEMA.COLUMNS
        where   TABLE_NAME = @tableName
                AND
                DATA_TYPE IN(''char'',''varchar'',''nchar'',''nvarchar'')
        order
        by      ORDINAL_POSITION
        for xml path('''')
        )
---- remove last ", "
set     @sql = LEFT( @sql, LEN(@SQL)-1)
print @sql
---- uncomment next line to execute the query
--exec (@sql)


这篇关于将表中的所有数据都更改为大写的查询是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆