Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 select statements within a function issue

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2011-05-08 : 19:40:20
I am getting the following issue, when i tried the following within a function:
select statements included within a function cannot return data to a client.

-----Here is a bit within the function i am trying to use.

SET @output = select DATEDIFF(Day, GetDate(), @RESULTDAYS)
return @output

Thank you very much for the helpful info.

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2011-05-08 : 19:58:13
Sorry, i need to put the select within the brackets. It is working now.

SET @output = (select DATEDIFF(Day, GetDate(), @RESULTDAYS))
return @output

Thank you.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-08 : 20:00:28
You can also do:

SELECT @output = DATEDIFF(Day, GetDate(), @RESULTDAYS)

or

SET @output = DATEDIFF(Day, GetDate(), @RESULTDAYS)

You don't need SELECT unless you're getting data from a table, view, or tabular function.
Go to Top of Page
   

- Advertisement -