Can I change the global variables values in SQL. [Resolved]

Posted by Allemahesh under Sql Server on 7/24/2013 | Points: 10 | Views : 886 | Status : [Member] [MVP] | Replies : 3
Can I change the global variables values in SQL. If yes, how?




Responses

Posted by: Satyapriyanayak on: 7/24/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
http://www.codeproject.com/KB/aspnet/global_variable_in_SSIS.aspx

If this post helps you mark it as answer
Thanks

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 7/26/2013 [Member] [MVP] Starter | Points: 50

Up
0
Down

Resolved
Nice question Allemahesh. You can say "no". There are two type of global variables, predefined can not be changed and User defined global you can not be created in sql server.

You can achieve with function or stored procedure. Once you will create your global variable with @@ that will be applicable for only one user session.

Creation of global variable with functions, see below is example

CREATE FUNCTION [dbo].[udf_JkGobalVariable] ( @CustomerID INT )

RETURNS INT
AS
BEGIN
DECLARE @ID INT
SET @ID = @CustomerID
RETURN @ID
END
GO


SELECT dbo.udf_JkGobalVariable(1000);


Refer below link for more infomation-
http://www.dotnetfunda.com/articles/article2015-global-variables-in-sql-server-part1.aspx

Hope you have understood.

Jitendra Kumar
If my post helps you, plz mark as an answer.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 7/24/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://www.mssqltips.com/sqlservertip/1443/integration-services-script-task-to-dynamically-build-package-variables/

If this post helps you mark it as answer
Thanks

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response