function help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kooter12000
    New Member
    • Feb 2008
    • 8

    function help

    Hi! everybody

    I have two tables in my data base. One table that keeps track of indian communities and the other table that keeps track of its community members. Each indian community is identified by a 3 digit number in the community table, And each community member is identified by a 10 digit number in the membership table. Here is what I would like to to. I would like to have the database check that the first 3 digits starting from the left to right of each community members number to make sure it matches with an indian community number in the community table before posting it in the database.

    kooter12000
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What do you have so far?

    -- CK

    Comment

    • shweta123
      Recognized Expert Contributor
      • Nov 2006
      • 692

      #3
      Hi,

      You can write a stored procedure for inserting a record into a database.
      Call the following function in order to check the 10 digit number in the membership table.

      e.g.
      Code:
      Create Function CheckId(@MainId varchar)
      returns int
      as
      Begin
              Declare @v_subId varchar(3);
              Declare @v_Id varchar(3);
      
              --Get SubId from main Id.Here you will get first 3 characters of the string.
              Select @v_subId =Substring(@MainId,1,3)
      
               --check that if above Id exists in the communitytable
              Select @v_Id = Id from  communitytable Where Id is like @v_subId 
              If  @v_newId Is Not NULL 
              BEGIN
                  Return 1
              END 
              ELSE
                 BEGIN
                  Return 0
              END 
           
      
      End

      Comment

      Working...