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 |
robertnzana
Starting Member
42 Posts |
Posted - 2008-05-22 : 22:11:40
|
I want to use 1 stored proc to run several update queries (using ASP.NET/.NET 3.5)I want to give it a few variables and use select variables in several UPDATE SQL queries.How can I do this?Thanks! |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-05-23 : 00:56:00
|
just put two or more update statements in the proc. did you try it? You can put any number of select/insert/update/delete statements in a single proc. elsasoft.org |
|
|
robertnzana
Starting Member
42 Posts |
Posted - 2008-05-23 : 10:26:27
|
So something like this is OK? Do I have to say "RUN", "GO", "EXECUTE", etc... after each one???ALTER PROCEDURE dbo.DeleteUserFromSystem ( @UserId as uniqueidentifier )AS -- delete from CompanyUsers DELETE FROM CompanyUsers WHERE UserId=@UserId -- delete from aspnet_UsersInRoles DELETE FROM aspnet_UsersInRoles WHERE UserId=@UserId -- delete from aspnet_Membership DELETE FROM aspnet_Membership WHERE UserId=@UserId -- delete from aspnet_Users DELETE FROM aspnet_Users WHERE UserId=@UserId RETURN |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-05-23 : 10:51:54
|
yes, that will work fine. you don't need any keywords after the statements. You may want to look at BOL for some more guidance on how to write procs. elsasoft.org |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-05-23 : 10:54:37
|
I might add that those comments don't add much - the delete statements speak for themselves don't they?I strive to add comments only when the add clarification to code blocks that need clarification. otherwise they just clutter: // add one to i++i; elsasoft.org |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-23 : 11:00:49
|
The only thing you have to remember is that you delete from tables according to referential integrity. E 12°55'05.25"N 56°04'39.16" |
|
|
robertnzana
Starting Member
42 Posts |
Posted - 2008-05-23 : 11:43:25
|
Thanks everyone! You all rock!!!! |
|
|
|
|
|