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 - 2003-06-19 : 07:32:18
|
| Mikael writes "We have some problem with a stored procedure!We want to create a proc.. that delete all information that a user has written in one of our tables.Want to to like this:exec sp_delete 'miboboy@online.no' in Q.ABut how can it be done in with stored procedureHave tried:Create procedure sp_deleteasdelete from tblInformationwhere username = @usernameSinc. Mikael the freebie! " |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2003-06-19 : 08:05:47
|
| -- sample data for testing create table #test(surname varchar(20), age int)insert into #test(surname, age)select 'garcia', 24union allselect 'el-bastardo', 15-- create spcreate procedure spUserDelete(@person varchar(20), @tablename varchar(20))asdeclare @sql varchar(1000)set @sql = ''select @sql = @sql + 'delete from ' + @tablename + ' where surname = ''' + @person + ''''exec(@sql)-- execute sp giving surname as parameterexec spUserDelete 'garcia', '#test'Edited by - Amethystium on 06/19/2003 08:35:05 |
 |
|
|
macka
Posting Yak Master
162 Posts |
Posted - 2003-06-19 : 08:24:14
|
| You shouldn't really prefix your stored procs with "sp_" as SQL Server will think its a system stored proc and go hunting in the master database before it looks at your database. Personally I use just an sp prefix . ie. spUserDeleteCheers,macka.--There are only 10 types of people in the world - Those who understand binary, and those who don't. |
 |
|
|
|
|
|