Solved

Variables for table and column names using the UPDATETEXT command

Posted on 2008-06-25
3
661 Views
Last Modified: 2008-06-26
I'm trying to use updatetext to replace some text in text columns in a number of different tables.  Obviously there is some looping involved.  At the heart of the loop I want to execute something like this:

      updatetext @TableName.@ColumnName @ptr @pos @txtlen @ntxt

I get this error using this arrangement:

      Server: Msg 170, Level 15, State 1, Line 134
      Line 134: Incorrect syntax near '@TableName'.

If I use an actual table name and column name, the statement appears to work.  However, I need to be able to substitute a new table name for each loop, so I'm back to the drawing board if I can't use a variable instead.

1)  Is it not possible with the updatetext command to use variables for the table and column names?

2)  If it's not possible, what other approach might I take to automate this task?

Thanks.

Scott
0
Comment
Question by:conderscott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21868872
you cannot use variables there.
the only approach with variables would be to build the dynamic sql, however that fails with the reference to the ntext parameter.
so, the only real solution is to have 1 procedure per table/column you want to do this.
0
 

Author Comment

by:conderscott
ID: 21873921
angelIII:

Thanks for the comment.  You're right.  I have tried the dynamic route and it seems to fail due to the binary @ptr variable.

Another idea:  if I loaded the records one at a time into a temp table, could I use updatetext on the temp table?  That way the table would always have the same name.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21874204
sorry, but I had tried that also ... no go.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question