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.
| Author |
Topic |
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2005-04-21 : 21:23:46
|
| I keep getting an error says:Server: Msg 170, Level 15, State 1,Line 14Line 14: Incorrect syntax near '@sql'.Server: Msg 156, Level 15, State 1, Line 17Incorrect syntax near the keyword 'end'What I am doing wrong?-------------------------------------------------------------------declare @col varchar(10)declare @table varchar(10)declare @sql varchar(200)declare cc cursorfast_forwardforselect a.name as [column],b.name as [Table] from syscolumns a join sysobjects b on a.id = b.id where a.name = 'Pat_id'open CCfetch next from cc into @col,@tablewhile @@FETCH_sTATUS = 0begin @sql = '''update ''[@Table]''' 'set ''[@col]'' = rtrim(ltrim(''[@col]'')''' fetch next from cc into @col,@tableendclose ccdeallocate ccprint @sql |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-04-21 : 21:30:40
|
| It's the same problem you have here:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=48467And the solution is the same as in that thread: post your table structure, and a description of what you're trying to accomplish. I can tell you now you'll be banging your head on a wall trying to get this working, and you'll only end up with a concussion. |
 |
|
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2005-04-21 : 23:31:22
|
| This statement:@sql = '''update ''[@Table]''' 'set ''[@col]'' = rtrim(ltrim(''[@col]'')'''should be changed to this:SET @sql = 'update [' + @Table + '] set [' + @col + '] = rtrim(ltrim([' + @col + ']))'Also, I assume you will want to execute this sql statement within the WHILE loop:EXEC @sqlAnd you should make your variable lengths (varchar(10)) longer. |
 |
|
|
|
|
|
|
|