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 within a function Expand / Collapse
Author
Message
Posted Friday, November 30, 2007 6:23 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
i am calling the dbo.mycustomertest with some code and its giving me a string output instead i need it to execute the next function which is inside the function

-----------------------------------------------------------------------------
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')

Answer : select * from
dbo.employee ()

I want the output of the function- select * from dbo.employee()
----------------------------------------------------
create function dbo.employee()
returns table
as
return
select * from employees
---------------------------------------------------

create function dbo.myorders()
returns table
as
return
select * from orders
Post #428063
Posted Friday, November 30, 2007 3:06 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, March 21, 2014 6:50 AM
Points: 451, Visits: 513
Change function definition to:


create function dbo.mycustomertest (@code varchar(10))
returns table
as

declare @sqlCmd nvarchar(4000)

select @sqlCmd = (case when @code= 'brm' then 'select * from
dbo.employee ()'
when @code='crm' then 'select * from dbo.myorder()'
else 'unknown'
end)

exec (@sqlCmd)

Post #428356
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse