Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 450615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:53:12+00:00 2026-05-12T21:53:12+00:00

I have a table in my warehouse that has columns in all uppercase. It

  • 0

I have a table in my warehouse that has columns in all uppercase. It scripts out like this:

CREATE TABLE [dbo].[Outlet](
    [OUTLET_KEY] [varchar](10) NOT NULL,
    [OUTLET] [varchar](8) NULL,
    [CITY_CODE] [varchar](4) NULL,
    [OUTLET_NAME] [varchar](25) NULL,
    [COUNTRY_CODE] [varchar](3) NULL,
    [EXTENDED_CATEGORY_CODE] [varchar](2) NULL,
    [PHONE_NUMBER] [varchar](17) NULL
) ON [PRIMARY]

I want to change the case of the columns in the table to a much more readable format

  • Outlet_Key
  • Outlet
  • City_Code
  • Outlet_Name
  • Country_Code …….

There are about 15 tables and about 200 columns. How do I change the case for all of them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:53:12+00:00Added an answer on May 12, 2026 at 9:53 pm

    Give this a shot:

    CREATE FUNCTION dbo.Get_Proper_Cased_String
    (@my_string VARCHAR(MAX))
    RETURNS VARCHAR(MAX)
    AS
    BEGIN
        DECLARE
            @work_string    VARCHAR(MAX),
            @final_string   VARCHAR(MAX),
            @position       SMALLINT
    
        SET @final_string = ''
        SET @position = CHARINDEX(' ', @my_string)
    
        WHILE (@position > 0)
        BEGIN
            SET @work_string = LEFT(@my_string, @position - 1)
    
            IF (@work_string <> '')
                SET @final_string = @final_string + ' ' + UPPER(SUBSTRING(@work_string, 1, 1)) + LOWER(SUBSTRING(@work_string, 2, LEN(@work_string) - 1))
    
            SET @my_string = RIGHT(@my_string, LEN(@my_string) - @position)
    
            SET @position = CHARINDEX(' ', @my_string)
        END
    
        /* changed this to LTRIM to remove trailing space that was getting converted to underscore */
        SET @final_string = LTRIM (@final_string + ' ' + UPPER(SUBSTRING(@my_string, 1, 1)) + LOWER(SUBSTRING(@my_string, 2, LEN(@my_string) - 1)))
    
        RETURN @final_string
    END
    GO
    
    SELECT
         'EXEC sp_rename ''' + O.name + '.' + C.name + ''', ''' + REPLACE(dbo.Get_Proper_Cased_String(REPLACE(C.name, '_', ' ')), ' ', '_') + ''', ''COLUMN'''
    FROM
        sys.objects O
    INNER JOIN sys.columns C ON
        C.object_id = O.object_id
    WHERE
        O.object_id = OBJECT_ID('<table_name>')
    

    This code assumes that the only non-character value that you have is “_” and that you don’t have successive underscores (i.e., MY____COLUMN would give the wrong results).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one data warehouse table that contain one row for each item sold.
We have a MySQL database that has two tables, Warehouse and Crate Warehouse: WarehouseID
I have the following table CREATE TABLE [dbo].[LogFiles_Warehouse]( [id] [int] IDENTITY(1,1) NOT NULL, [timestamp]
This is a FACT Table in a Data Warehouse It has a composite index
I'm working rearchitecting a reporting/data warehouse type database. We currently have a table that
I have a table with 5 columns :- Country Code Language Warehouse ActiveFrom ActiveTo
I have a database in access 2010. A have a table that has some
I have table with around 70 000 rows. There is 6000 rows that i
I have table and this table contain result column with some entries. I just
I have table with 300 000 records (MyISAM). I get record from this table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.