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 |
|
manju3606
Yak Posting Veteran
78 Posts |
Posted - 2011-11-03 : 06:28:17
|
| I am using below sp to delete data in table on rowid base so now what i want to do is i have to change db_id in query only but this sp runs only in aaaa database in ssms i cant change databse id in ssms. So what i have to do please tell me USE [AAAA]GO/****** Object: StoredProcedure [dbo].[Rowid_delete_sp] Script Date: 11/03/2011 15:48:36 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[Rowid_delete_sp](@IN_from int,@IN_to int,@IN_tablename varchar(1000))asbegin declare @query varchar(max) set @query='With CTE as (select *,ROW_NUMBER() over (order by (select 1)) as rn from '+@IN_tablename+') select * into #Raghu from CTE WHERE rn between '+CONVERT(VARCHAR(100), @IN_from)+' and '+CONVERT(VARCHAR(100), @IN_to)+'alter table #Raghu drop column rn select * from #Raghu drop table #Raghu' execute (@query) endThanksManju |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2011-11-03 : 07:25:50
|
| Why oh WHY would you do this???Using dynamic sql for deletes?? it boggles the mind...http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-03 : 07:32:43
|
| or if databases are in same server, you can use sp_Msforeachdb procedure to iterate the code through each db------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2011-11-03 : 08:12:11
|
| Where do want to use Db_id in your query? |
 |
|
|
|
|
|