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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-02-25 : 09:00:11
|
| SP writes "Hii passed a parameter(table name) in store procedure and i want use this table name in store proc. how will use..??example :if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[itemcorrect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[itemcorrect]GOSET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOcreate procedure itemcorrect(@sptable varchar(40))as begindeclare @oitemcode varchar(16)declare @ditemcode varchar(16)declare @ritemcode varchar(16)declare item cursor forselect item_code,item_code1 from data2/*declare item1 cursor for *//*select item_code from item_mst*/open itemfetch next from item into @ditemcode,@ritemcodewhile @@fetch_status=0beginselect item_code from @sptable where item_code=@ditemcodeif (@@rowcount)>0 update @sptable set item_code=@ritemcode where item_code=@ditemcode fetch next from item into @ditemcode,@ritemcodeendClose item Deallocate itemendGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO do u have solution for above..???" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-02-25 : 09:29:10
|
| Why are you using a cursor?If you want to do it like this then I suggest you shouldn't be using t-sql - do it in the client instead.To use a table variable you will have to use dynamic sql - look at the faqs.select @sql = 'select * from ' + @tableexec (@sql)put it into a temp table if you need to work on it.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|