SQL Server Forums
Profile | Register | 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 Administration
 how to create temporary function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rajadadi
Starting Member

India
30 Posts

Posted - 05/03/2010 :  08:44:26  Show Profile  Reply with Quote
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

India
52320 Posts

Posted - 05/03/2010 :  09:57:59  Show Profile  Reply with Quote
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

USA
169 Posts

Posted - 05/03/2010 :  10:54:55  Show Profile  Visit RobertKaucher's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000