Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Stored procedure searching comments with wildcards

$
0
0

Hello I need to create a stored procedure and incorporate it into a report where the users can look up certain values in comment fields. This is what I have so far but I am getting errors, maybe I'm tired and I'm not seeing what the issue is can anyone help please

[code]

CREATE PROCEDURE
[dbo].[SearchAccomplishments]
@Enter_Accomplishments text =null,
@Beginning_CompletionDate datetime = null,
@End_CompletionDate datetime = null

AS

   IF patindex( '*', @Enter_Accomplishments ) > 0

      BEGIN

         SET @Enter_Accomplishments = replace( @Enter_Accomplishments, '*', '%' )
        
         SELECT     A.CompletionDate, A.Accomplishments, A.accomplishID, A.Participant
FROM         Accomplishments_tbl A

  WHERE (Accomplishments LIKE @Enter_Accomplishments)
   AND (Accomplishments LIKE @Enter_Accomplishments)
 AND (@Beginning_CompletionDate    IS NULL OR CompletionDate >= @Beginning_CompletionDate)
 and (@End_CompletionDate IS NULL OR CompletionDate <= @End_CompletionDate)

      END

   ELSE

      BEGIN

        IF patindex( '*', @Enter_Accomplishments ) > 0
   SET @Enter_Accomplishments = replace( @Enter_Accomplishments, '*', '%' )
 SELECT     A.CompletionDate, A.Accomplishments, A.accomplishID, A.Participant
FROM         Accomplishments_tbl A

 WHERE (Accomplishments LIKE @Enter_Accomplishments)
   AND (Accomplishments LIKE @Enter_Accomplishments)
 AND (@Beginning_CompletionDate    IS NULL OR CompletionDate >= @Beginning_CompletionDate)
 and (@End_CompletionDate IS NULL OR CompletionDate <= @End_CompletionDate)


 
ORDER BY CompletionDate

 END

[/code]


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>