Hi,
Don't worry about the vars, they are defined,
the following line give me an err of "Incorrect syntax near '.'."
Goal: to rename nonstardard column name.
EXEC sp_rename '+@tbuffer+'.['+@cbuffer+']','+Replace(+@cbuffer+','%[^A-Za-z0-9_#$@]%','')',
'COLUMN';
Thanks. 6 3056
Doug Baroter (qw********@boxfrog.com) writes: Don't worry about the vars, they are defined, the following line give me an err of "Incorrect syntax near '.'." Goal: to rename nonstardard column name.
EXEC sp_rename '+@tbuffer+'.['+@cbuffer+']','+Replace(+@cbuffer+','%[^A-Za-z0-9_#$@]%','')', 'COLUMN';
You can only pass constants and variables as parameters to stored procedures.
You cannot pass an expression as a parameter, but you must put everything
in variables.
Furthermore, replace() only handles fixed strings, and does not have
any capacbilities to find patterns.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Erland,
Thanks for the quick response. Please my further question below.
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn**********************@127.0.0.1>... Doug Baroter (qw********@boxfrog.com) writes: Don't worry about the vars, they are defined, the following line give me an err of "Incorrect syntax near '.'." Goal: to rename nonstardard column name.
EXEC sp_rename '+@tbuffer+'.['+@cbuffer+']','+Replace(+@cbuffer+','%[^A-Za-z0-9_#$@]%','')', 'COLUMN'; You can only pass constants and variables as parameters to stored procedures. You cannot pass an expression as a parameter, but you must put everything in variables.
Are you saying I should do something like
set @tbuffer = '''+@tbuffer+''';
set @cbuffer = '''+@cbuffer+''';
and then
EXEC sp_rename @tbuffer+'.['+@cbuffer+']' ... Furthermore, replace() only handles fixed strings, and does not have any capacbilities to find patterns.
Since replace can't do the job for this case, what other option do I
have to remove the non-standard character(s), I've looked at charindex
and stuff function, could they fit in here or a better way to do it?
Doug Baroter (qw********@boxfrog.com) writes: Are you saying I should do something like set @tbuffer = '''+@tbuffer+'''; set @cbuffer = '''+@cbuffer+'''; and then EXEC sp_rename @tbuffer+'.['+@cbuffer+']' ...
Rather:
SELECT @old_name = 'tbl.' + <whatever>
SELECT @new_name = <whichever>
EXEC sp_rename @old_name, @new_name, 'column'
Since replace can't do the job for this case, what other option do I have to remove the non-standard character(s), I've looked at charindex and stuff function, could they fit in here or a better way to do it?
Unfortunately, SQL is poor for this task. You are probably better off
if you write some program in Perl, Visual Basic, VBscript, C or whatever
is your favourite client language.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Thanks, Erland, pls see below.
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn********************@127.0.0.1>... Doug Baroter (qw********@boxfrog.com) writes: Are you saying I should do something like set @tbuffer = '''+@tbuffer+'''; set @cbuffer = '''+@cbuffer+'''; and then EXEC sp_rename @tbuffer+'.['+@cbuffer+']' ... Rather:
SELECT @old_name = 'tbl.' + <whatever> SELECT @new_name = <whichever> EXEC sp_rename @old_name, @new_name, 'column'
Unfortunately the tbl name is dynamically determined. But as you
recommended below, I just use a non-SQL language to take care of the
whole problem except one minor one, that is, I haven't got the RegExp
part fully completed. Since replace can't do the job for this case, what other option do I have to remove the non-standard character(s), I've looked at charindex and stuff function, could they fit in here or a better way to do it?
Unfortunately, SQL is poor for this task. You are probably better off if you write some program in Perl, Visual Basic, VBscript, C or whatever is your favourite client language.
Doug Baroter (qw********@boxfrog.com) writes: SELECT @old_name = 'tbl.' + <whatever> SELECT @new_name = <whichever> EXEC sp_rename @old_name, @new_name, 'column'
Unfortunately the tbl name is dynamically determined.
SELECT @old_name = @tbl + '.' + @column
The point is that when you come to sp_rename you must have a single
value.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
OK. Thanks.
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn**********************@127.0.0.1>... Doug Baroter (qw********@boxfrog.com) writes: SELECT @old_name = 'tbl.' + <whatever> SELECT @new_name = <whichever> EXEC sp_rename @old_name, @new_name, 'column'
Unfortunately the tbl name is dynamically determined.
SELECT @old_name = @tbl + '.' + @column
The point is that when you come to sp_rename you must have a single value. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sinister |
last post by:
The examples in the online manual all seem to use double quotes, e.g. at
http://us3.php.net/preg_replace
Why? (The behavior is different with single quotes, and presumably simpler
to...
|
by: Jakanapes |
last post by:
Hi all,
I'm looking for a way to scan a block of text and replace all the
double quotes (") with single quotes (').
I'm using PHP to pull text out of a mySQL table and then feed the text
into...
|
by: sankofa |
last post by:
hi, i can't seem to be able to escape my single quote properly... is it
even possible in javascript?
this is a portion of my code..
var DLEWIS="Pastor Lewis";
.... Sermon is a yser-defined...
|
by: Joel |
last post by:
Hi,
I incorporated a function in my code that whenever I use a string variable
in an sql statement if the string contains a single quote it will encase it
in double quotes else single quotes.
...
|
by: Greg |
last post by:
I keep getting an error when I have a tick mark in a text value that I am
searching for in my XPath Query.
Example:
<Authors>
<Author LastName="O'Donnel">
<Author LastName="Smith">...
|
by: claus.hirth |
last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement
in order to play with the PREPARE and EXECUTE keywords.
In transcript 1 below the call to that stored procedure does not...
|
by: Jason |
last post by:
I have several tables with quite a few fields and I'm getting errors when
trying to insert records with single quotes in the data like: name = John
O'Henry or a city name of O'Fallen
So I went...
|
by: Justin Fancy |
last post by:
Hi everyone,
I need to replace all instances of a double quote(") with two single
quotes('') in a text file. I already have some replacements of strings
going on, but I tried this one, but the...
|
by: Reporter |
last post by:
I got the following example from http://www.evolt.org/article/User_Friendly_Forms_in_PHP/20/60144/index.html
:
echo '<tr><td>First name:</td><td><input type="text" name="first_name"...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |