Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Error when updating the table

Author  Topic 

svicky9
Posting Yak Master

232 Posts

Posted - 2006-10-27 : 06:05:47

Hi Friends

I am trying to create the following procedure for

updating a col for a particular table

The procedure is as follows:

create procedure vic_ltrim
@col_name varchar(100)
,@table_name varchare(100)

as

update @table_name
set @col_name = ltrim(@col_name)


I get the error as

Server: Msg 137, Level 15, State 2, Procedure vic_ltrim, Line 8
Must declare the variable '@table_name'.


Should i change the Data Type of the Table name???

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-27 : 06:10:19
Does noone no longer design proper databases?

set @sqlcmd = 'update [' + @table_name + '] set [' + @col_name + '] = ltrim(@col_name)'
exec (@sqlcmd)

http://www.sommarskog.se/dynamic_sql.html


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2006-10-27 : 07:40:35
hi Peso,

can u tell me, why we can't pass table name runtime. i have just checked that, we can pass column name at runtime. why SQL server does not support this?

Mahesh
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-27 : 07:52:14
>> why we can't pass table name runtime.

It is possible with Dynamic SQL
Read that link fully


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-10-27 : 09:15:49
It's not about whether it is possible or not, its about why you want to do it this way...If you are forced to do this by design, it's sign of bad design !

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -