469,125 Members | 1,835 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,125 developers. It's quick & easy.

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
Jan 5 '09 #1
2 1032
ck9663
2,878 Expert 2GB
What do you have so far?

-- CK
Jan 5 '09 #2
shweta123
692 Expert 512MB
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.
Expand|Select|Wrap|Line Numbers
  1. Create Function CheckId(@MainId varchar)
  2. returns int
  3. as
  4. Begin
  5.         Declare @v_subId varchar(3);
  6.         Declare @v_Id varchar(3);
  7.  
  8.         --Get SubId from main Id.Here you will get first 3 characters of the string.
  9.         Select @v_subId =Substring(@MainId,1,3)
  10.  
  11.          --check that if above Id exists in the communitytable
  12.         Select @v_Id = Id from  communitytable Where Id is like @v_subId 
  13.         If  @v_newId Is Not NULL 
  14.         BEGIN
  15.             Return 1
  16.         END 
  17.         ELSE
  18.            BEGIN
  19.             Return 0
  20.         END 
  21.  
  22.  
  23. End
Jan 6 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Joneseyboy | last post: by
7 posts views Thread by Mike D. | last post: by
4 posts views Thread by George Durzi | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.