472,145 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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 1078
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.