Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Function Expand / Collapse
Author
Message
Posted Friday, November 30, 2007 9:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, August 15, 2009 1:42 AM
Points: 7, Visits: 79
Want a function to execute another function based on the passing variable.


create function dbo.mycustomertest (@code varchar(10))
returns table
as
return
select (case when @code= 'brm' then 'select * from
dbo.employee ()'
when @code='crm' then 'select * from dbo.myorder()'
else 'unknown'
end) as col1
--------------------------------------------------
select * from dbo.mycustomertest ('brm')

Result.-- select * from dbo.mycustomertest ('brm')

Instead i need the output of [select * from dbo.employees ]the above function
----------------------------------------------------
create function dbo.employee()
returns table
as
return
select * from employees
---------------------------------------------------

create function dbo.myorders()
returns table
as
return
select * from orders


-------------------------------------------------


Post #428197
Posted Friday, November 30, 2007 10:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:57 PM
Points: 6,998, Visits: 13,949
Functions don't allow for dynamic calls. You're going to need to do that logic OUTSIDE of a function.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #428234
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse