That line should have read:

IF @toid > 0
SET @query = @query + 'AND M.ToID = ' + convert(varchar,@toid)

  ----- Original Message ----- 
  From: Robertson-Ravo, Neil (RX) 
  To: '[EMAIL PROTECTED]' 
  Sent: Friday, February 20, 2004 11:19 AM
  Subject: [cfmail] RE: [ cf-dev ] Stored Procedures


  Hi Allan,

  Not sure if you have pasted everything but you havent declared @toaccountid.
  The SP will not parse unless its in there.

  CREATE PROC GetMessages

  @fromid int,
  @toid int,
  @searchtext varchar,
  @toaccountid INT

  AS 

  DECLARE @query varchar(1000)
   
  SET @query = 'SELECT * FROM Messages M '
  SET @query = @query + ' WHERE 1=1 '

  IF @fromid > 0
  SET @query = @query + 'AND M.FromID = ' + convert(varchar,@fromid)

  IF @toaccountid > 0
  SET @query = @query + 'AND M.ToID = ' + convert(varchar,@toid)

  IF @searchtext <> ''
      SET @query = @query +  'AND M.Message LIKE'  + "'%" + @searchtext + "%'"

  SET @query = @query + ' ORDER BY M.MessageID'
  EXEC(@query)
  GO


   

  -----Original Message-----
  From: Allan Cliff [mailto:[EMAIL PROTECTED] 
  Sent: 20 February 2004 10:15
  To: CF - List
  Subject: [ cf-dev ] Stored Procedures

  I am trying to move a query to a Stored Procedure.

  I want to add a LIKE to it but doesn't seem to work.
  It seems to find the first letter only and then if it finds that it works

  Example:

  Message Body: "My name is Allan"

  Search Text: "a" - Found 1 result
  Search Text: "b" - Found 0 results
  Search Text: "Allan" - Found 1 result
  Search Text: "Alllan" - Found 1 result
  Search Text: "asakjhfsiuhieqworg" - Found 1 result

  Help Please. I know its Friday. And it really is Friday today.

  Allan

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

  CREATE PROC GetMessages

  @fromid int,
  @toid int,
  @searchtext varchar

  AS 

  DECLARE @query varchar(1000)
   
  SET @query = 'SELECT * FROM Messages M '
  SET @query = @query + ' WHERE 1=1 '

  IF @fromid > 0
  SET @query = @query + 'AND M.FromID = ' + convert(varchar,@fromid)

  IF @toaccountid > 0
  SET @query = @query + 'AND M.ToID = ' + convert(varchar,@toid)

  -----------------------------------------------
  **THIS SYNTAX DOESN'T WORK**
  IF @searchtext <> ''
      SET @query = @query +  'AND M.Message LIKE '  + "'%" + @searchtext +
  "%'"

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

  SET @query = @query + ' ORDER BY M.MessageID'
  EXEC(@query)
  GO
  This e-mail is from Reed Exhibitions (Oriel House, 26 The Quadrant,
  Richmond, Surrey, TW9 1DL, United Kingdom), a division of Reed Business,
  Registered in England, Number 678540.  It contains information which is
  confidential and may also be privileged.  It is for the exclusive use of the
  intended recipient(s).  If you are not the intended recipient(s) please note
  that any form of distribution, copying or use of this communication or the
  information in it is strictly prohibited and may be unlawful.  If you have
  received this communication in error please return it to the sender or call
  our switchboard on +44 (0) 20 89107910.  The opinions expressed within this
  communication are not necessarily those expressed by Reed Exhibitions.
  Visit our website at http://www.reedexpo.com

  -- 
  ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  For human help, e-mail: [EMAIL PROTECTED]

Reply via email to