[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

Use VBScript In Access To Add Another Column and Populate It's Rows

I have a table that has a Name column with stuff like "$25 Gift Card".

I need to add another column to the table of type Number with the 25.

I was thinking of using VBscript but, not sure how to actually pull the name, split it and stuff the 25 into the same row.

There are about 140000 rows and possibly more depending.

Any ideas or pointers?
0
cefranklin
Asked:
cefranklin
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
you can use a user defined function to that

place this codes in a regular module

function getNumValue(xCol)
if xcol & ""="" then getNumValue=null : exit function

getNumvalue=split(xcol," ")(0)

end function

now run a query

select ColumnName, getNumvalue([ColumName]) as newCol
from tableName


basically, that is the general idea.. you may need to tweak the codes depending on the output you want and the manner the data was inputted
0
 
cefranklinAuthor Commented:
Kind of funny that I just posted this and figured it out.  I am using the Mid() function for SQL then altering the column to a number type to get rid of any spaces.

q_SalesByDate = "" & _
        "SELECT V_SITE.SITENAME, V_SALE.SITE, V_ITEM.NAME, V_ITEM.GLACCOUNT, V_SALE.LOGDATE, Mid([V_SALEITEMS].[NOTE],1,7) AS [NOTE], Mid([V_ITEM].[NAME],2,3) AS [TOTAL] " & _
        "INTO T_SalesByDate " & _
        "FROM ((V_SALE " & _
        "INNER JOIN V_SALEITEMS ON (V_SALE.OBJID = V_SALEITEMS.SALEID) " & _
        "AND (V_SALE.SITE = V_SALEITEMS.SITE)) " & _
        "INNER JOIN V_SITE ON (V_SALEITEMS.SITE = V_SITE.ID) AND (V_SALE.SITE = V_SITE.ID)) " & _
        "INNER JOIN V_ITEM ON V_SALEITEMS.ITEM = V_ITEM.OBJID " & _
        "WHERE (((" & sites & ") " & _
        "AND (" & giftcards & ") " & _
        "AND ((V_SALE.LOGDATE) Between #" & Me.txtFromDate.Value & "# And #" & Me.txtToDate.Value & "#)) " & _
        "ORDER BY V_SALE.LOGDATE DESC;"
    
    
    'MsgBox q_SalesByDate
    DoCmd.RunSQL q_SalesByDate
    
    q_FixTotalColumnInSales = "ALTER TABLE T_SalesByDate ALTER COLUMN TOTAL NUMBER;"
    
    DoCmd.RunSQL q_FixTotalColumnInSales

Open in new window

0
 
cefranklinAuthor Commented:
Figured it out myself, sorry.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now