Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reusing code

Status
Not open for further replies.

againstTheWind

Programmer
Jun 22, 2006
42
US

I have a query that I will have to reuse several times and I am wondering what the most elegant way to do this usually is - perhaps declaring a variable to store the SELECT statement?

If so, how would I use this variable?

Thanks!
 

Jim - thanks for the suggestion. I was hoping more for something like declaring a variable for the SELECT statement and then using it a few times. The code isn't long enough to make a stored procedure.

Any suggestions?

Thanks!
 
There is no minimum length requirement for stored procedures. The fact that you need to reuse the code is enough. You could also consider a user defined function.

Otherwise you are looking at storing the sql in a variable and using EXECUTE or sp_executesql to run it as required.
 
I'm not an administrator on this specific server so I think that leaves creating a stored procedure out.

Any other ideas?
 
Don't feel stupid, againstTheWind - you learned something. Stupid people don't ask questions and don't learn.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top