Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
Register Now and get your question answered!
Username:
Password:
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  

rcjay272
Starting Member

USA
1 Posts

Posted - 01/12/2013 :  12:53:05  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 01/12/2013 :  13:39:05  Show Profile  Reply with Quote
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
  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.18 seconds. Powered By: Snitz Forums 2000