Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends,

I want to generate pin for an MLM site, for this i want to use master..spt_values table, but dont have any idea about it.

can any one suggest me, how to auto-generate pin using spt_values or any tutorial for this.
Posted

hello,

is there any fix prefix for generating pin

like

MLM101
MLM102

anyways use random() in sqlserver.
 
Share this answer
 
Comments
abhishekagrwl25 10-Apr-12 1:47am    
yes there is prefix based on joining kit.... like if joining kit name is scalar then pin should be...sc101, sc102....
ok..
then in a sql server create a procedure for inserting into your table name
like below
SQL
create proc SP_GeneratePin

@kit nvarchar(6)
.
.
.
as

begin
insert into yourtable(columns,..,..) values (param1,param2)

declare @iden 
@iden=@@identity

if(@kit='scalar')

update yourtable table pin= 'sc' + convert(char,@iden) where youridentityid=@iden

else if(@kit='scalar')

update yourtable table pin= 'abc' + convert(char,,@iden) where youridentityid=@iden 

end



let me know if there is any error come across
 
Share this answer
 
v2
You can something like:


1. Have a column that has identity specification as true and increment value 1.
2. now since this column will always have unique values you can either pad it to append it to some string so that you get the PIN as per your requirements.
 
Share this answer
 
Comments
abhishekagrwl25 10-Apr-12 3:32am    
actuly i want to know about use of spt_values table and how to use it...??
VB
master..spt_values
may not be a right choice for you. It is an undocument procedure meant for internal use. Such procedures may be dropped/modified in future releases without any notification.

Use rownumber function. Check this link
http://msdn.microsoft.com/en-us/library/ms186734.aspx[^]

If you are keen on using spt_values see this link http://sqldbpool.com/2010/12/15/master-spt_values-system-table/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900