sirbounty
asked on
sql sproc
I'm trying to setup a stored procedure where I can pass in one value and it gets used with a wildcard.
The data could be anywhere within one or multiple fields.
If I run a select statement with the data in there, it works, but it's not working in my sproc...
basically setup like this:
@GID nvarchar(50) = NULL
SELECT DISTINCT DisplayName, EntryID FROM Table1 WHERE EntryID in (
SELECT [EntryID] FROM Table2 WHERE
Owner LIKE '%@GID%' OR
Owner2 LIKE '%@GID%', etc...
)
The data could be anywhere within one or multiple fields.
If I run a select statement with the data in there, it works, but it's not working in my sproc...
basically setup like this:
@GID nvarchar(50) = NULL
SELECT DISTINCT DisplayName, EntryID FROM Table1 WHERE EntryID in (
SELECT [EntryID] FROM Table2 WHERE
Owner LIKE '%@GID%' OR
Owner2 LIKE '%@GID%', etc...
)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CREATE PROC ProcName
AS
BEGIN
DECLARE @GID nvarchar(50) = NULL
SELECT DISTINCT a.DisplayName, a.EntryID FROM Table1 a
INNER JOIN FROM Table2 b ON a.EntryID = b.EntryID
WHERE
(Owner LIKE '%' + @GID + '%' OR Owner IS NULL) OR
(Owner2 LIKE '%' + @GID + '%' OR Owner2 IS NULL) OR
.............
.............
END