467,917 Members | 1,387 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,917 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.

Jan 5 '09 #1
  • viewed: 994
2 Replies
Expert 2GB
What do you have so far?

-- CK
Jan 5 '09 #2
Expert 512MB

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.

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);
  8.         --Get SubId from main Id.Here you will get first 3 characters of the string.
  9.         Select @v_subId =Substring(@MainId,1,3)
  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 
  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
By using this site, you agree to our Privacy Policy and Terms of Use.