473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Total Replacing

Hi,

Is it possible to do from one script? We have a set of user's tables like
"tbl%". We can get this list very easy using this script:

SELECT name FROM sysobjects WHERE xtype = 'U' AND name LIKE 'tbl%' ORDER BY
name;

We need to change some column names if these names are in a special list
that we have. What can we do? Use FOR EACH ROW? Or what?

So, I need to get a column list for each table and check if every column
name is equal to one of the names from the list and then if YES replace it
by something or add some symbol to this name. Terrible or possible?

Regards,
Dmitri
Jul 20 '05 #1
4 2105
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message news:<UgEnb.94948$Ms2.65755@fed1read03>...
Hi,

Is it possible to do from one script? We have a set of user's tables like
"tbl%". We can get this list very easy using this script:

SELECT name FROM sysobjects WHERE xtype = 'U' AND name LIKE 'tbl%' ORDER BY
name;

We need to change some column names if these names are in a special list
that we have. What can we do? Use FOR EACH ROW? Or what?

So, I need to get a column list for each table and check if every column
name is equal to one of the names from the list and then if YES replace it
by something or add some symbol to this name. Terrible or possible?

Regards,
Dmitri


Here's one possible approach:

1. Create a table to hold the old and new column names:

create table dbo.TempNames (OldName sysname, NewName sysname)

2. Insert the old and new column names you want:

insert into dbo.TempNames select 'Column1', 'Column1UpdatedName'
insert into dbo.TempNames select 'Column2', 'Column3'
etc.

3. Execute this query, then copy and paste the output, check it and
execute:

select 'exec sp_rename ''' + i.TABLE_NAME + '.' + i.COLUMN_NAME + ''',
''' + t.NewName + ''', ''column'''
from INFORMATION_SCHEMA.COLUMNS i
join dbo.TempNames t
on i.COLUMN_NAME = t.OldName

This makes some assumptions about your logic, but it should give you
an idea.

Simon
Jul 20 '05 #2
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message news:<UgEnb.94948$Ms2.65755@fed1read03>...
Hi,

Is it possible to do from one script? We have a set of user's tables like
"tbl%". We can get this list very easy using this script:

SELECT name FROM sysobjects WHERE xtype = 'U' AND name LIKE 'tbl%' ORDER BY
name;

We need to change some column names if these names are in a special list
that we have. What can we do? Use FOR EACH ROW? Or what?

So, I need to get a column list for each table and check if every column
name is equal to one of the names from the list and then if YES replace it
by something or add some symbol to this name. Terrible or possible?

Regards,
Dmitri


Here's one possible approach:

1. Create a table to hold the old and new column names:

create table dbo.TempNames (OldName sysname, NewName sysname)

2. Insert the old and new column names you want:

insert into dbo.TempNames select 'Column1', 'Column1UpdatedName'
insert into dbo.TempNames select 'Column2', 'Column3'
etc.

3. Execute this query, then copy and paste the output, check it and
execute:

select 'exec sp_rename ''' + i.TABLE_NAME + '.' + i.COLUMN_NAME + ''',
''' + t.NewName + ''', ''column'''
from INFORMATION_SCHEMA.COLUMNS i
join dbo.TempNames t
on i.COLUMN_NAME = t.OldName

This makes some assumptions about your logic, but it should give you
an idea.

Simon
Jul 20 '05 #3
Hi

The easiest way to do this is probably easiest to do using a CURSOR and EXEC
a call to sp_rename.
See Books Online for more information regarding cursors.

Using the INFORMATION_SCHEMA.COLUMNS view should help cut down the need to
link multiple system tables.

John
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message
news:UgEnb.94948$Ms2.65755@fed1read03...
Hi,

Is it possible to do from one script? We have a set of user's tables like
"tbl%". We can get this list very easy using this script:

SELECT name FROM sysobjects WHERE xtype = 'U' AND name LIKE 'tbl%' ORDER BY name;

We need to change some column names if these names are in a special list
that we have. What can we do? Use FOR EACH ROW? Or what?

So, I need to get a column list for each table and check if every column
name is equal to one of the names from the list and then if YES replace it
by something or add some symbol to this name. Terrible or possible?

Regards,
Dmitri

Jul 20 '05 #4
Hi

The easiest way to do this is probably easiest to do using a CURSOR and EXEC
a call to sp_rename.
See Books Online for more information regarding cursors.

Using the INFORMATION_SCHEMA.COLUMNS view should help cut down the need to
link multiple system tables.

John
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message
news:UgEnb.94948$Ms2.65755@fed1read03...
Hi,

Is it possible to do from one script? We have a set of user's tables like
"tbl%". We can get this list very easy using this script:

SELECT name FROM sysobjects WHERE xtype = 'U' AND name LIKE 'tbl%' ORDER BY name;

We need to change some column names if these names are in a special list
that we have. What can we do? Use FOR EACH ROW? Or what?

So, I need to get a column list for each table and check if every column
name is equal to one of the names from the list and then if YES replace it
by something or add some symbol to this name. Terrible or possible?

Regards,
Dmitri

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rutger Claes | last post by:
How do I stop the SAX parser from replacing entities such as &#xE3; and &#xA9;. When I use &gt; and a default_handler, the default_handler is called and I can just print the data. Entities as &#xA9;...
3
by: John Livermore | last post by:
From javascript in IE, I have a need to hijack the onclick event for an element and replace it dynamically with my own. I have tried the following... control.onclick = 'myHandler();'; but...
1
by: beavenour | last post by:
I am looking for some help creating a more universal function out of this lame attempt at javascript. I have little experience with javascript and want to be able to universalize this function. ...
7
by: Rob Meade | last post by:
Hi all, Been a long time since I've been here... /me waves to all.. Ok - my conundrum.. I have a form where a user can enter text and BB codes...for example:
10
by: giancarlodirisioster | last post by:
Can someone help me modify this for future Usenet archival and to help me solve what I don't know? <form name="addform" method="POST" action="./submit.php"> <input type="text" name="Box 1"...
2
by: worli | last post by:
Hi All, I have a strange requirement. I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc.... ( each input number range from 1 to 10 ). lets take a simple case where all inputs will...
1
by: CaptainDahlin | last post by:
I know the basics about access reports and putting page totals in the page footers. What I can't figure out is along with the current page total to display the previous page total: At the bottom...
1
by: patelgaurav85 | last post by:
Hi, I want to convert xml in one format into another xml format shown below Input xml : <Name> <Name1> <Name11>Name11</Name11> <Name12>Name12</Name12>
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.