Showing posts with label assign. Show all posts
Showing posts with label assign. Show all posts

Friday, March 30, 2012

How can I retrieve a function return value from an executed string?

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

Wednesday, March 28, 2012

How can I read value from one XML and assign to another XML.

I need to read value from one master XML and assign to another XML.

I am planning to move some of my application's business logic to SQL Server side.

I have informations stored in xml field. There is a procedure which accepts the xml input, and return the xml with values from the master xml. Please help me to achieve this.

-- master XML

declare @.x_master xml

set @.x_master='<ROOT><NAME>111</NAME><ADDRESS>2222</ADDRESS><TYPE>3333</TYPE><COUNTRY/></ROOT>'

-- input XML (this can be any tag from the master XML)

declare @.x xml

set @.x='<ROOT><NAME></NAME><ADDRESS/></ROOT>'

--set @.x='<ROOT><NAME/><COUNTRY/></ROOT>'

--set @.x='<ROOT><ADDRESS/><COUNTRY/><TYPE/></ROOT>'

It sounds like you want to interpret <ROOT><NAME></NAME><ADDRESS/></ROOT> as a query. You could generate XQuery by concatenating strings together. You could insert path expressions into the context of <NAME></NAME>. But you need to make sure it is safe from SQL injection since you will be dynamically constructing SQL/XQuery using string concatenation.

sql

Monday, March 19, 2012

How can I lock and release table

How can I lock and release table
I need to assign user table to acess table only one time and after access
the table will lock
and how to release the table after lock
Thank you for all thinking shareIt's hard to suggest something without more info. Take a look at lock hints
in the BOL
"Pure_haven" <u32445@.uwe> wrote in message news:6f1b82bbe0020@.uwe...
> How can I lock and release table
> I need to assign user table to acess table only one time and after
> access
> the table will lock
> and how to release the table after lock
> Thank you for all thinking share
>