DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

getting values from tables

This is a discussion on getting values from tables within the ASP Development forums, part of the Programming & Scripting category; Hi, I am giving discount codes to special customers. So I will be giving a specified codes from the table. ...

Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

  #1  
Old February 1st, 2009, 12:15 PM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 462
Rep Power: 2
todd2006 is an unknown quantity at this point
Default getting values from tables

Hi,

I am giving discount codes to special customers. So I will be giving a specified codes from the table. The number of the codes will be different each time.

someone will get 2 codes someone will get 45 or someone will get 75.

so my query will be like this
strnum=trim(request.form("noofcodes")

Select top strnum * from codes

how do i save them in different variables.

Can i create the variables on fly and store the codes in them

can someone tell me how I make this happen

todd
Reply With Quote
  #2  
Old February 2nd, 2009, 12:17 AM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 462
Rep Power: 2
todd2006 is an unknown quantity at this point
Default

So what I want to do is get the 50 or 75 codes from one table and add it to another table with the USERID

I have the userid stored into a variable.
Reply With Quote
  #3  
Old February 2nd, 2009, 12:44 AM
dr_rock's Avatar
Drunk Barn Owl
 
Join Date: Jun 2008
Location: Melbourne, Australia
Posts: 92
Rep Power: 2
dr_rock will become famous soon enough
Default

Use a count statement to fint the number of rows then use a select statement to pull the codes,
Code:
strSQL = "select count(ID) from wherever where something = true;select code from wherever where something = true"
Create an array with userID and Code fields, Ubound rowcount value then run through your recordset of codes and mix with the USERID

Code:
Redim arrList(1,rst(0))

Set rst = rst.NextRecordset
For intCount = 0 to rst.EOF
   arrList(0,intCount) = UserID
   arrList(1,intCount) = rst("code")
  rst.MoveNext
Loop
Then you can stick it in a table or do whatever you like in the array.

Does that kind of sound like what you are looking for?
Reply With Quote
  #4  
Old February 2nd, 2009, 01:16 AM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 462
Rep Power: 2
todd2006 is an unknown quantity at this point
Default

I tried it like this

Code:
sqltext = "select top 3 * from Codes"
Set rs = Conn.Execute(sqltext)

strnewadd ="select * from Add_Codes;"
Set rsnewAdd = Server.CreateObject("ADODB.Recordset")
With rsnewAdd
.Source="Add_Codes"
.CursorType = 2
.LockType = 3
End With
rsnewAdd.Open strnewadd, Conn

For I = 0 to rs.Fields.Count - 1
    redim preserve ARR(I)
  	rsnewAdd.AddNew
	rsnewAdd("Reg_Id") = sID
	rsnewAdd("Free_Codes") = rs.Fields(I).Name
	
	rsnewAdd.Update

Next

I tried for 3 codes it didnt add the codes in the free_Codes field

what am i doing wrong
Reply With Quote
  #5  
Old February 2nd, 2009, 01:34 AM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 462
Rep Power: 2
todd2006 is an unknown quantity at this point
Default

Ok this code only adds one code and not 3

Code:
sqltext = "select top 3 DiscountCode from Codes"
Set rs = Conn.Execute(sqltext)

strnewadd ="select * from Add_Codes;"
Set rsnewAdd = Server.CreateObject("ADODB.Recordset")
With rsnewAdd
.Source="Add_Codes"
.CursorType = 2
.LockType = 3
End With
rsnewAdd.Open strnewadd, Conn

For I = 0 to rs.Fields.Count - 1
   	rsnewAdd.AddNew
	rsnewAdd("Reg_Id") = sID
	rsnewAdd("Free_Codes") = rs.Fields(I)
	rsnewAdd.Update

Next
can someone tell me what i am doing wrong in the loop
Reply With Quote
  #6  
Old February 2nd, 2009, 02:14 AM
dr_rock's Avatar
Drunk Barn Owl
 
Join Date: Jun 2008
Location: Melbourne, Australia
Posts: 92
Rep Power: 2
dr_rock will become famous soon enough
Default

How about this?

Code:
sqltext = "select top 3 DiscountCode from Codes"
Set rs = Conn.Execute(sqltext)
sqltextoutput = ""

For I = 0 to rs.Fields.Count - 1

  sqltextoutput = sqltextoutput & "Insert Into Add_Codes (Reg_Id,Free_Codes) values ("&sID&","&rs.Fields(I)&");"

Next

Response.write(sqltextoutput)
If len(sqltextoutput) > 0 Then Conn.Execute(sqltextoutput)

Comments on this post
jmurrayhead agrees: good one

Last edited by dr_rock; February 2nd, 2009 at 02:16 AM. Reason: table & field names added
Reply With Quote
  #7  
Old February 2nd, 2009, 02:23 AM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 462
Rep Power: 2
todd2006 is an unknown quantity at this point
Default

Ok i used this code and it worked

Code:
Set oCodesRs = oConn.Execute("SELECT TOP " & strnum & "* FROM codes;")

If Not oCodesRs.EOF Then
 Do While Not oCodesRs.EOF 
  sCode = oCodesRs("code")

  oConn.Execute("INSERT INTO othertable (UserID,Code) VALUES(" & iUserID & ",'" & sCode & "');")

 oCodesRs.MoveNext
 Loop
End If
how do i delete the codes that i inserted from the codes table

because i dont want to give the same codes to a different person
Reply With Quote
  #8  
Old February 2nd, 2009, 06:33 PM
dr_rock's Avatar
Drunk Barn Owl
 
Join Date: Jun 2008
Location: Melbourne, Australia
Posts: 92
Rep Power: 2
dr_rock will become famous soon enough
Default

Code:
sqltext = "select top 3 DiscountCode from Codes"
Set rs = Conn.Execute(sqltext)
sqltextoutput = ""

For I = 0 to rs.Fields.Count - 1

  sqltextoutput = sqltextoutput & "Insert Into Add_Codes (Reg_Id,Free_Codes) values ("&sID&","&rs.Fields(I)&");Delete From DiscountCode Where ID = " & rs.Fields("ID") &";"

Next

Response.write(sqltextoutput)
If len(sqltextoutput) > 0 Then Conn.Execute(sqltextoutput)
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Spliced tables, paged results dr_rock SQL Code Samples 0 September 16th, 2008 02:19 AM
Pulling from multiple tables... bryceowen SQL Development 2 September 15th, 2008 07:57 PM
Form for multiple tables and queries nboscaino Microsoft Access 1 August 21st, 2008 06:55 PM
finding values todd2006 ASP Development 2 June 23rd, 2008 02:03 AM
Permissions on Tables, Stored Procedures, etc. theChris Microsoft SQL Server 2 March 24th, 2008 11:49 AM


All times are GMT -4. The time now is 01:50 AM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2