SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Stored procedure in a function


Stored procedure in a function

Author
Message
Minnu
Minnu
Mr or Mrs. 500
Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)

Group: General Forum Members
Points: 567 Visits: 950
Hi,

i have a report developed in Report Builder 3.0, having 3 parameters, 2 are drop down and 1 is text box,

user need to select 3 parameters, for text box parameter, user may enter like "Bike" or "20*Bike"

if Bike : output should be "Bike 1, bike 444, 2012 bike,.....
if 20*Bike : output should be "2012 Bike, 2011 Bike, 20 Bike123, 20 Bike 983,etc...


to get the above logic am using below stored procedure

create procedure dbo.STORED_PROC_NAME
(
@sstrg varchar(100)
)
as
begin
set nocount on;

--declare @strg varchar(100) = 'Catalog',
set @sstrg = '%' + REPLACE( @sstrg, '*', '%') + '%'

SELECT project_name
FROM groups
WHERE project_name like @sstrg
end


Am using stored procedure in report builder,

stored procedure query:
------------------------------------------
SELECT a,b,c
FROM groups
WHERE
a IN (SELECT value from dbo.Fn_tsp_orderhistory('''+@a+''','',''))
and
b IN ((SELECT value from dbo.Fn_tsp_orderhistory('''+@b+''','',''))
and
c LIKE (SELECT value from dbo.Fn_tsp_orderhistory(EXEC STORED_PROC_NAME
('''+@c+'''))'

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

FUNCTION :"Fn_tsp_orderhistory is using for multi-value parameter.


My requirement is : how to use above stored procedure in below where condition ::

and c LIKE (SELECT value from dbo.Fn_tsp_orderhistory(EXEC STORED_PROC_NAME
('''+@c+'''))'



Please help,
H4K
H4K
SSC Veteran
SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)

Group: General Forum Members
Points: 247 Visits: 567
You don't have to use a SP. you can just replace following code:
SELECT value from dbo.Fn_tsp_orderhistory(EXEC STORED_PROC_NAME
('''+@c+''')

WITH

SELECT value from dbo.Fn_tsp_orderhistory( '%' + REPLACE( @c, '*', '%') + '%')

BI Developer
SSRS, SSIS, SSAS, IBM Cognos, IBM Infosphere Cubing services, Crystal reports, IBM DB2, SQL Server, T-SQL
Please visit... ApplyBI
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28920 Visits: 39984
Are you sure about that?

copy and paste it to SSMS...that stops right away with a syntax check, since the EXEC command cannot exist inside the parameter list.


H4K (8/29/2012)
You don't have to use a SP. you can just replace following code:
SELECT value from dbo.Fn_tsp_orderhistory(EXEC STORED_PROC_NAME
('''+@c+''')

WITH

SELECT value from dbo.Fn_tsp_orderhistory( '%' + REPLACE( @c, '*', '%') + '%')


Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Luis Cazares
Luis Cazares
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17008 Visits: 19122
Please, don't go step by step.
You have 3 posts very similar and it seems to me that you're not giving us the entire problem.
If we're aware of the whole context, we can give you better ideas.

PS. I'm glad you liked my solution, a simple thanks would have been appreciated.


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
H4K
H4K
SSC Veteran
SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)

Group: General Forum Members
Points: 247 Visits: 567
Lowell (8/29/2012)
Are you sure about that?

copy and paste it to SSMS...that stops right away with a syntax check, since the EXEC command cannot exist inside the parameter list.

To answer @Lowell, I didn't check the original query with EXEC command. I just suggest an alternate solution. Thanks for pointing that out :-)

I received and replied to the private message from the creator of this post:

I replied:

Actually there is a problem with the apostrophes you have used

try this:
Set @project_name_cond=' and (project_name LIKE
(SELECT value from dbo.Fn_tsp_orderhistory(''' + '%' + REPLACE( @original_project_name, '*', '%') + '%' + ''')'



I know the above pasted is private message, but wanted to share that maybe this issue is resolved now Unsure. i think as no reply came.

BI Developer
SSRS, SSIS, SSAS, IBM Cognos, IBM Infosphere Cubing services, Crystal reports, IBM DB2, SQL Server, T-SQL
Please visit... ApplyBI
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search