Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query table 1 for a value and use that value to de
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 01/12/2013 :  12:53:05  Show Profile  Reply with Quote

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'


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,


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/12/2013 :  13:39:05  Show Profile  Reply with Quote
just make script like procedure as below

CREATE PROC DeleteUserDetails
@User varchar(100)
Delete from othertable o
join user u
on = o.uid
where u.uName=@User

then call it from automated job as

EXEC DeleteUserDetails 'johndoe'

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000