Function Execution in Select Clause

5 pts.
Tags:
SQL Server
I stuck in a scenario. Can somebody help me out. I have a table contains column Id, FncName Id column contains integer value and FncName contains Scalar Function name. I want to select a row from table and in result set I need the result of execution of that function. Sample data is given below:
CREATE TABLE AA (Id INT, FncName VARCHAR(255))
INSERT INTO AA VALUES (1,'aa_utcdate')
INSERT INTO AA VALUES (2,'aa_date')
GO
CREATE FUNCTION aa_utcdate ()
RETURNS DATETIME
AS
BEGIN

DECLARE @A DATETIME
SELECT @A = GETUTCDATE()
RETURN @A
END

GO

CREATE FUNCTION AA_DATE ()
RETURNS DATE
AS
BEGIN
DECLARE @A DATE

SELECT @A = GETDATE()

RETURN @A
END

-- Query to execute

SELECT id,exec(FncName) FROM AA

-- Result Set Required
1, 2013-11-13 10:08:01.860
2, 2013-11-13 15:08:01.863

Answer Wiki

Thanks. We'll let you know when a new response is added.

I don’t think it’s possible, although I’m happy to be proved wrong, in one select statement

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following