Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2003
    Posts
    18

    Exclamation Unanswered: Check if a caractere exists in a SQL field

    Hi everybody ,


    I would like with a Stored procedure check if a caracter exists in a string stored in a SQL server field.

    Example :


    My field contains the caracters "ABCDEF" ,

    I would like to check if "C" is in this string.

    Tank U

  2. #2
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227
    select charindex('C', 'ABCDEF') which would return 3. If the first expression is not found in the second, it returns zero.
    Johan

  3. #3
    Join Date
    Aug 2003
    Posts
    18

    check if a caracter exists in a sql field

    Thanks joan but i would like to make the expression 2 a variable wich contains my column name

    Remeber the syntax must respect syntax of stored procedure

    This is my stored procedure code :
    @level is the caracter i search
    @droits is the caracters contained in my field

    IF (@Level <> "nothing")
    BEGIN
    SELECT @droits=droits FROM USERS WHERE UserID=@UserID
    IF NOT SELECT charindex(@Level, @droits)


    BEGIN
    SELECT Progress=2,Errormsg="Pas l'droits."
    RETURN
    END
    SELECT @AccessNumber = @AccessNumber + 1
    UPDATE USERLOG SET Accessdt=GETDATE(),AccessNumber=@AccessNumber WHERE SessionID=@SessionID
    SELECT Progress=0,userID=@userID
    RETURN
    END


    can you help me please ?

  4. #4
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227
    Code:
    DECLARE @pos
    IF (@Level <> "nothing")
    BEGIN
      SELECT @droits=droits FROM USERS WHERE UserID=@UserID
      SELECT @pos = charindex(@Level, @droits)
      IF  @pos > 0
      BEGIN
        SELECT Progress=2,Errormsg="Pas l'droits."
      RETURN
      END
    
      SELECT @AccessNumber = @AccessNumber + 1
      UPDATE USERLOG SET Accessdt=GETDATE(), AccessNumber=@AccessNumber WHERE SessionID=@SessionID
      SELECT Progress=0,userID=@userID
      RETURN
    END
    Johan

  5. #5
    Join Date
    Aug 2003
    Posts
    18

    Wink Check caracter in sql field

    It works

    Thank U guy : ))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •