[thelist] Stored procedure

darren darren at web-bitch.co.uk
Fri Feb 7 08:39:01 CST 2003


On Friday, February 7, 2003 at 13:22, Stevenson Ngila wrote:

SN> if i have a string "56,57,58,59" and i have "56", how can i loop
SN> through the first string and check if the 56 exists in the string using an
SN> sql stored procedure?

if this is ms sql server...

   declare @aString varchar(100)
   declare @toFind  varchar(50)

   set @aString = '56,57,58,59'
   set @toFind  = '56'

   -- make sure we have a , at the start and end of the strings
   -- means we don't match 56 in 5676,1234...

   set @aString = ',' + @aString + ','
   set @toFind  = ',' + @toFind  + ','

   if PatIndex('%' + @toFind + '%', @aString) > 0
   BEGIN
      -- we have the string
   END
   ELSE
   BEGIN
      -- we don't have the string
   END

hth,

darren.




More information about the thelist mailing list