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 Administration
 how to create temporary function

Author  Topic 

rajadadi
Starting Member

30 Posts

Posted - 2010-05-03 : 08:44:26
how to create temporary function


Actually i am using prod server not able to create function. but i need to use some functions. so is it possible to create temp function. and then to call that function

rajesh

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-03 : 09:57:59
why not write logic in main query itself then?

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

Go to Top of Page

RobertKaucher
Posting Yak Master

169 Posts

Posted - 2010-05-03 : 10:54:55
You could use sp_executesql to build a temporary SProc or function.


DECLARE @myVar AS INT
DECLARE @test AS nvarchar(500)
DECLARE @paramDef nvarchar(500)

SET @paramDef = N'@myParam INT'
SET @myVar = 10248

SET @test = N'USE Northwind; SELECT * from dbo.Orders where dbo.Orders.OrderID = @myParam'

EXEC sp_executesql @test, @paramDef, @myParam = @myVar;


http://msdn.microsoft.com/en-us/library/ms175170.aspx

You declare your variables, set up your SQl string to execute and then run it against sp_executesql. The syntax of the SProc is

sp_executesql [VARIABLE WITH SQL SOMMAND], [VARIABLE WITH DEFINITION OF THE PARAMETER], [VARIABLE WITH VALUE TO BE PASSED TO THE PARAMETER] 


===
http://www.ElementalSQL.com/
Go to Top of Page
   

- Advertisement -