Hello!
Suppose that I have the name of an UDF (@.Function) which returns an scalar value and accepts just one parameter. How can I execute and assign the return value to a variable?
I tried the following, but it did not work:
declare @.Receptor as sql_variant
set @.Receptor=execute('select ' + @.Function + '(10)')
Thanks a lot in advance.The function is not completely qualified (DB name, owner)
Try:
declare @.Receptor as sql_variant
set @.Receptor = database_name.dbo.Function(@.in_param_value)
A user defined function can be used like any other pre-defined function
Originally posted by EMoscosoCam
Hello!
Suppose that I have the name of an UDF (@.Function) which returns an scalar value and accepts just one parameter. How can I execute and assign the return value to a variable?
I tried the following, but it did not work:
declare @.Receptor as sql_variant
set @.Receptor=execute('select ' + @.Function + '(10)')
Thanks a lot in advance.sql
Showing posts with label udf. Show all posts
Showing posts with label udf. Show all posts
Friday, March 30, 2012
Wednesday, March 21, 2012
How can I obtain the login name of the caller of my UDF written in a CLR language?
I am using MS SQL Server 2005.
Is there a way to obtain the login name of the caller of my user
defined function implement in managed C++?
I know I can get the information using the code segment below but I
want to avoid connecting back to the database for performance reasons.
String^ queryString = "select suser_sname()"
SqlConnection conn = gcnew SqlConnection(connectionString);
SqlCommand command = new SqlCommand(queryString, connection);
conn.Open();
SqlDataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnect ion);
while (reader.Read())
{
reader[0];
}
Thanks,
Steven
Examine using the Security object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160176423.328986.327470@.i42g2000cwa.googlegr oups.com...
>I am using MS SQL Server 2005.
> Is there a way to obtain the login name of the caller of my user
> defined function implement in managed C++?
> I know I can get the information using the code segment below but I
> want to avoid connecting back to the database for performance reasons.
> String^ queryString = "select suser_sname()"
> SqlConnection conn = gcnew SqlConnection(connectionString);
> SqlCommand command = new SqlCommand(queryString, connection);
> conn.Open();
> SqlDataReader reader =
> command.ExecuteReader(CommandBehavior.CloseConnect ion);
> while (reader.Read())
> {
> reader[0];
> }
> Thanks,
> Steven
>
|||Darn Spell Checker.
Look into the SecurityPrinicipal object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:uBNLaka6GHA.4620@.TK2MSFTNGP02.phx.gbl...
> Examine using the Security object.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "smaully" <smauldin@.ingrian.com> wrote in message
> news:1160176423.328986.327470@.i42g2000cwa.googlegr oups.com...
>
|||Arnie,
That will return the Windows user not the sql login.
-Steve
|||I read that that is what you desired; "obtain the login name of the caller".
There was nothing to indicate you were using SQL Logins.
Since that is know to and in SQL Server, and not known to the client
application, the only way is to ask SQL Server to provide it. That may
require a 'wasted' round trip. You might call a stored procedure, have the
stored procedure call the UDF, and pass the SQL Login back as a output
parameter.
Of course, I don't know how you are using the UDF, so that may not work for
you.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160415121.924478.80610@.m7g2000cwm.googlegrou ps.com...
> Arnie,
> That will return the Windows user not the sql login.
> -Steve
>
Is there a way to obtain the login name of the caller of my user
defined function implement in managed C++?
I know I can get the information using the code segment below but I
want to avoid connecting back to the database for performance reasons.
String^ queryString = "select suser_sname()"
SqlConnection conn = gcnew SqlConnection(connectionString);
SqlCommand command = new SqlCommand(queryString, connection);
conn.Open();
SqlDataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnect ion);
while (reader.Read())
{
reader[0];
}
Thanks,
Steven
Examine using the Security object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160176423.328986.327470@.i42g2000cwa.googlegr oups.com...
>I am using MS SQL Server 2005.
> Is there a way to obtain the login name of the caller of my user
> defined function implement in managed C++?
> I know I can get the information using the code segment below but I
> want to avoid connecting back to the database for performance reasons.
> String^ queryString = "select suser_sname()"
> SqlConnection conn = gcnew SqlConnection(connectionString);
> SqlCommand command = new SqlCommand(queryString, connection);
> conn.Open();
> SqlDataReader reader =
> command.ExecuteReader(CommandBehavior.CloseConnect ion);
> while (reader.Read())
> {
> reader[0];
> }
> Thanks,
> Steven
>
|||Darn Spell Checker.
Look into the SecurityPrinicipal object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:uBNLaka6GHA.4620@.TK2MSFTNGP02.phx.gbl...
> Examine using the Security object.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "smaully" <smauldin@.ingrian.com> wrote in message
> news:1160176423.328986.327470@.i42g2000cwa.googlegr oups.com...
>
|||Arnie,
That will return the Windows user not the sql login.
-Steve
|||I read that that is what you desired; "obtain the login name of the caller".
There was nothing to indicate you were using SQL Logins.
Since that is know to and in SQL Server, and not known to the client
application, the only way is to ask SQL Server to provide it. That may
require a 'wasted' round trip. You might call a stored procedure, have the
stored procedure call the UDF, and pass the SQL Login back as a output
parameter.
Of course, I don't know how you are using the UDF, so that may not work for
you.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160415121.924478.80610@.m7g2000cwm.googlegrou ps.com...
> Arnie,
> That will return the Windows user not the sql login.
> -Steve
>
How can I obtain the login name of the caller of my UDF written in a CLR language?
I am using MS SQL Server 2005.
Is there a way to obtain the login name of the caller of my user
defined function implement in managed C++?
I know I can get the information using the code segment below but I
want to avoid connecting back to the database for performance reasons.
String^ queryString = "select suser_sname()"
SqlConnection conn = gcnew SqlConnection(connectionString);
SqlCommand command = new SqlCommand(queryString, connection);
conn.Open();
SqlDataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
reader[0];
}
Thanks,
StevenExamine using the Security object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>I am using MS SQL Server 2005.
> Is there a way to obtain the login name of the caller of my user
> defined function implement in managed C++?
> I know I can get the information using the code segment below but I
> want to avoid connecting back to the database for performance reasons.
> String^ queryString = "select suser_sname()"
> SqlConnection conn = gcnew SqlConnection(connectionString);
> SqlCommand command = new SqlCommand(queryString, connection);
> conn.Open();
> SqlDataReader reader =
> command.ExecuteReader(CommandBehavior.CloseConnection);
> while (reader.Read())
> {
> reader[0];
> }
> Thanks,
> Steven
>|||Darn Spell Checker.
Look into the SecurityPrinicipal object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:uBNLaka6GHA.4620@.TK2MSFTNGP02.phx.gbl...
> Examine using the Security object.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "smaully" <smauldin@.ingrian.com> wrote in message
> news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>|||Arnie,
That will return the Windows user not the sql login.
-Steve|||I read that that is what you desired; "obtain the login name of the caller".
There was nothing to indicate you were using SQL Logins.
Since that is know to and in SQL Server, and not known to the client
application, the only way is to ask SQL Server to provide it. That may
require a 'wasted' round trip. You might call a stored procedure, have the
stored procedure call the UDF, and pass the SQL Login back as a output
parameter.
Of course, I don't know how you are using the UDF, so that may not work for
you.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160415121.924478.80610@.m7g2000cwm.googlegroups.com...
> Arnie,
> That will return the Windows user not the sql login.
> -Steve
>
Is there a way to obtain the login name of the caller of my user
defined function implement in managed C++?
I know I can get the information using the code segment below but I
want to avoid connecting back to the database for performance reasons.
String^ queryString = "select suser_sname()"
SqlConnection conn = gcnew SqlConnection(connectionString);
SqlCommand command = new SqlCommand(queryString, connection);
conn.Open();
SqlDataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
reader[0];
}
Thanks,
StevenExamine using the Security object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>I am using MS SQL Server 2005.
> Is there a way to obtain the login name of the caller of my user
> defined function implement in managed C++?
> I know I can get the information using the code segment below but I
> want to avoid connecting back to the database for performance reasons.
> String^ queryString = "select suser_sname()"
> SqlConnection conn = gcnew SqlConnection(connectionString);
> SqlCommand command = new SqlCommand(queryString, connection);
> conn.Open();
> SqlDataReader reader =
> command.ExecuteReader(CommandBehavior.CloseConnection);
> while (reader.Read())
> {
> reader[0];
> }
> Thanks,
> Steven
>|||Darn Spell Checker.
Look into the SecurityPrinicipal object.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:uBNLaka6GHA.4620@.TK2MSFTNGP02.phx.gbl...
> Examine using the Security object.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "smaully" <smauldin@.ingrian.com> wrote in message
> news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>|||Arnie,
That will return the Windows user not the sql login.
-Steve|||I read that that is what you desired; "obtain the login name of the caller".
There was nothing to indicate you were using SQL Logins.
Since that is know to and in SQL Server, and not known to the client
application, the only way is to ask SQL Server to provide it. That may
require a 'wasted' round trip. You might call a stored procedure, have the
stored procedure call the UDF, and pass the SQL Login back as a output
parameter.
Of course, I don't know how you are using the UDF, so that may not work for
you.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160415121.924478.80610@.m7g2000cwm.googlegroups.com...
> Arnie,
> That will return the Windows user not the sql login.
> -Steve
>
How can I obtain the login name of the caller of my UDF written in a CLR language?
I am using MS SQL Server 2005.
Is there a way to obtain the login name of the caller of my user
defined function implement in managed C++?
I know I can get the information using the code segment below but I
want to avoid connecting back to the database for performance reasons.
String^ queryString = "select suser_sname()"
SqlConnection conn = gcnew SqlConnection(connectionString);
SqlCommand command = new SqlCommand(queryString, connection);
conn.Open();
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
reader[0];
}
Thanks,
StevenExamine using the Security object.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>I am using MS SQL Server 2005.
> Is there a way to obtain the login name of the caller of my user
> defined function implement in managed C++?
> I know I can get the information using the code segment below but I
> want to avoid connecting back to the database for performance reasons.
> String^ queryString = "select suser_sname()"
> SqlConnection conn = gcnew SqlConnection(connectionString);
> SqlCommand command = new SqlCommand(queryString, connection);
> conn.Open();
> SqlDataReader reader => command.ExecuteReader(CommandBehavior.CloseConnection);
> while (reader.Read())
> {
> reader[0];
> }
> Thanks,
> Steven
>|||Darn Spell Checker.
Look into the SecurityPrinicipal object.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:uBNLaka6GHA.4620@.TK2MSFTNGP02.phx.gbl...
> Examine using the Security object.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "smaully" <smauldin@.ingrian.com> wrote in message
> news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>>I am using MS SQL Server 2005.
>> Is there a way to obtain the login name of the caller of my user
>> defined function implement in managed C++?
>> I know I can get the information using the code segment below but I
>> want to avoid connecting back to the database for performance reasons.
>> String^ queryString = "select suser_sname()"
>> SqlConnection conn = gcnew SqlConnection(connectionString);
>> SqlCommand command = new SqlCommand(queryString, connection);
>> conn.Open();
>> SqlDataReader reader =>> command.ExecuteReader(CommandBehavior.CloseConnection);
>> while (reader.Read())
>> {
>> reader[0];
>> }
>> Thanks,
>> Steven
>|||Arnie,
That will return the Windows user not the sql login.
-Steve|||I read that that is what you desired; "obtain the login name of the caller".
There was nothing to indicate you were using SQL Logins.
Since that is know to and in SQL Server, and not known to the client
application, the only way is to ask SQL Server to provide it. That may
require a 'wasted' round trip. You might call a stored procedure, have the
stored procedure call the UDF, and pass the SQL Login back as a output
parameter.
Of course, I don't know how you are using the UDF, so that may not work for
you.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160415121.924478.80610@.m7g2000cwm.googlegroups.com...
> Arnie,
> That will return the Windows user not the sql login.
> -Steve
>
Is there a way to obtain the login name of the caller of my user
defined function implement in managed C++?
I know I can get the information using the code segment below but I
want to avoid connecting back to the database for performance reasons.
String^ queryString = "select suser_sname()"
SqlConnection conn = gcnew SqlConnection(connectionString);
SqlCommand command = new SqlCommand(queryString, connection);
conn.Open();
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
reader[0];
}
Thanks,
StevenExamine using the Security object.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>I am using MS SQL Server 2005.
> Is there a way to obtain the login name of the caller of my user
> defined function implement in managed C++?
> I know I can get the information using the code segment below but I
> want to avoid connecting back to the database for performance reasons.
> String^ queryString = "select suser_sname()"
> SqlConnection conn = gcnew SqlConnection(connectionString);
> SqlCommand command = new SqlCommand(queryString, connection);
> conn.Open();
> SqlDataReader reader => command.ExecuteReader(CommandBehavior.CloseConnection);
> while (reader.Read())
> {
> reader[0];
> }
> Thanks,
> Steven
>|||Darn Spell Checker.
Look into the SecurityPrinicipal object.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Arnie Rowland" <arnie@.1568.com> wrote in message
news:uBNLaka6GHA.4620@.TK2MSFTNGP02.phx.gbl...
> Examine using the Security object.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
>
> "smaully" <smauldin@.ingrian.com> wrote in message
> news:1160176423.328986.327470@.i42g2000cwa.googlegroups.com...
>>I am using MS SQL Server 2005.
>> Is there a way to obtain the login name of the caller of my user
>> defined function implement in managed C++?
>> I know I can get the information using the code segment below but I
>> want to avoid connecting back to the database for performance reasons.
>> String^ queryString = "select suser_sname()"
>> SqlConnection conn = gcnew SqlConnection(connectionString);
>> SqlCommand command = new SqlCommand(queryString, connection);
>> conn.Open();
>> SqlDataReader reader =>> command.ExecuteReader(CommandBehavior.CloseConnection);
>> while (reader.Read())
>> {
>> reader[0];
>> }
>> Thanks,
>> Steven
>|||Arnie,
That will return the Windows user not the sql login.
-Steve|||I read that that is what you desired; "obtain the login name of the caller".
There was nothing to indicate you were using SQL Logins.
Since that is know to and in SQL Server, and not known to the client
application, the only way is to ask SQL Server to provide it. That may
require a 'wasted' round trip. You might call a stored procedure, have the
stored procedure call the UDF, and pass the SQL Login back as a output
parameter.
Of course, I don't know how you are using the UDF, so that may not work for
you.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"smaully" <smauldin@.ingrian.com> wrote in message
news:1160415121.924478.80610@.m7g2000cwm.googlegroups.com...
> Arnie,
> That will return the Windows user not the sql login.
> -Steve
>
Subscribe to:
Posts (Atom)