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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query table 1 for a value and use that value to de

Author  Topic 

rcjay272
Starting Member

1 Post

Posted - 2013-01-12 : 12:53:05
All,

I am new to creating scripts to run on SQL. My goal is to create a script that allows me to query one table for an "id" value and then run a delete statement on another table to delete a row.


These are the SQL commands I run manually and I would like to automate this so I don't have to get into SQL MGMT Studio each time.

select id from user where uName='johndoe'

Output
09123a6b

Delete from othertable where uid='09123a6b'

However.....I want to script this so I can run it like a batch file with a variable. Is this possible? Where do I start?

I would like something like this....this is just an example of how I think it should work.

c:\deleteuser.bat johndoe

Thank you,

Rob

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-12 : 13:39:05
just make script like procedure as below

[code]
CREATE PROC DeleteUserDetails
@User varchar(100)
AS
Delete from othertable o
join user u
on u.id = o.uid
where u.uName=@User
GO

then call it from automated job as

EXEC DeleteUserDetails 'johndoe'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -