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

Stored procedure in Where clause Expand / Collapse
Author
Message
Posted Wednesday, August 29, 2012 6:34 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 7:36 AM
Points: 229, Visits: 730
Hi,

below is the query to display the project_name where project_name matches the condition.

select project_name from Groups
where project_name like '%20%Catalog%'


below is the stored procedure using for search string.

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


i want to execute the same query with stored procedure

select project_name from Groups
where project_name like (EXEC STORED_PROC_NAME '%20%Catalog%')


Please help.
Post #1351566
Posted Wednesday, August 29, 2012 6:49 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, November 21, 2014 9:38 AM
Points: 6,861, Visits: 14,160
The stored procedure returns the result set you want - why complicate it (and double the execution time)?

You may have simplified things a little to help - in which case, you could run the results of the stored procedure into a #temp table and join to it in your query:

CREATE TABLE #Projects (project_name VARCHAR(stringsize))

INSERT INTO #Projects (project_name)
EXEC STORED_PROC_NAME '%20%Catalog%'

SELECT g.project_name
FROM Groups g
INNER JOIN #Projects p
ON p.project_name = g.project_name



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1351578
Posted Wednesday, August 29, 2012 12:43 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 12:29 PM
Points: 1,945, Visits: 3,121
In the early days, we had to load parameters into registers in the hardware. Why are you still doing that with local variables?

CREATE PROCEDURE Search_Project_Name
(@in_project_name_pattern VARCHAR(100))
AS
SELECT project_name
FROM Project_Groups
WHERE project_name
LIKE '%' + @in_project_name_pattern + '%';

But then why are you putting something this simple in a procedure and not just using the LIKE predicate?


Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1351844
Posted Thursday, August 30, 2012 3:15 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 3:45 AM
Points: 2,873, Visits: 5,188
CELKO (8/29/2012)
In the early days, we had to load parameters into registers in the hardware. Why are you still doing that with local variables?
...


Oh those old days,
They gone away.
But we sometimes do need this way,
To stop a proc to sniff the lot
So, query plan is what we thought





_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1352065
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse