Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
VBScript Function for Compound Primary Key
Old 05-07-2007, 05:22 PM VBScript Function for Compound Primary Key
wacara's Avatar
Novice Talker

Posts: 14
Name: Wanda
Location: Belvidere, IL
Trades: 0
I have 2 tables...the first is the Customer_Info Table and the primary Key is Quote_ID. The second table is the Quote_Requirements table which has a compound primary key (Quote_Id & DetailID). I am trying to write a function in VBScript that will increment the DetailID (i.e A, B, C etc.) part of the compound primary key so that the Quote_Id will be inserted as many times as the user creates a new detail for that Quote. Here's what I have right now. What is happening is when I test out the function it writes out a 'D' because of the first letter in CurrentID.

Code:
Function NewDetailID()
Dim MyNumber, MyChar
MyNumber = ASC("CurrentID")
MyChar = CHR(MyNumber + 1)
NewDetailID = MyChar

End Function
response.Write(NewDetailID)
I need some help in understanding what I am not doing correctly. Thank you.
__________________
you gotta see it before you see it or you never will see it...
wacara is offline
Reply With Quote
View Public Profile Visit wacara's homepage!
 
 
Register now for full access!
Old 05-07-2007, 05:56 PM Re: VBScript Function for Compound Primary Key
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,520
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
ASC("CurrentID") will always return 67 because "CurrentID" is a string literal that starts with "C"

If I have read the code correctly;

Code:
NewDetailID = CHR(ASC(right(CurrentID,1)) +1)
will get you what you need in a single line of code.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 05-07-2007 at 05:56 PM.. Reason: added code tags
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-07-2007, 07:59 PM Re: VBScript Function for Compound Primary Key
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Is there any reason in particular you're using character data instead of an integer for part of your key? Things would be much easier otherwise, and while a single-byte column is scalable, ints might take less CPU power.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 05-07-2007, 08:17 PM Re: VBScript Function for Compound Primary Key
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I don't understand why Quote_ID isn't the foreign key in the relationship and why DetailID (assuming it's autogenerated and/or incremental) isn't the primary key by itself.

Other than that, what Hirst said.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to VBScript Function for Compound Primary Key
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26504 seconds with 12 queries