Solved

How to execute a SQL Scalar Valued Function from SQL Management Studion query window

Posted on 2011-02-26
3
1,268 Views
Last Modified: 2012-05-11
I have created a scalar valued function which returns a single value and I execute it in a sproc. It works fine but I want to test it from a Query Window but I can't see how to do that.
When I type in "exec MyDatabase.dbo.fn_MyFunction" all I get in the results window is
"Command(s) completed successfully."
I would like to see the reults of the function. Thanks for any help.
0
Comment
Question by:AkAlan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34989470
If your function returned a VARCHAR(200) you would do something like:
DECLARE @Test VARCHAR(200)
EXEC @Test = MyDatabase.dbo.fn_MyFunction

PRINT @Test

Open in new window

0
 
LVL 26

Expert Comment

by:tigin44
ID: 34989472
you should call it like

select MyDatabase.dbo.fn_MyFunction
0
 
LVL 6

Author Closing Comment

by:AkAlan
ID: 34989478
I tried the other persons answer but I got an error
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question