Advertisement

02.21.2008 at 03:19PM PST, ID: 23183007
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How to Update Existing SQL Record using VB Script in Active X Script
Tags: VBScript, IE 7.0
I'm attempting to update existing records that are already in a SQL database through an Active X Script in SQL using VBScript. I do not want to add new records, I only want to update specific fields in records if they apply to the If / Then statement conditions set in the vbscript. The update is going to look for any records having a null import date. If so, it will run through the update statement and update any fields designated for every applicable record. I can open the recordset and my connection string is correct, but i cannot get it to loop through the entire database and update every record. I've tried cn.Execute, I've tried cn.AddNew / cn.Update nothing is working.If I use the .AddNew method - it tried to import new record with NULL value in primary key field. If I use .Execute "UPDATE....statement" I get EOF/BOF error.

Again, I only wish to update existing recordset values with hard values or with values created through if/then conditional statements.
Thanks!

1:
2:
3:
4:
5:
6:
7:
8:
9:
if len(rs("SSN")) < 9 then
	for i = 1 to 9 
              rs("SSN") = "0" & rs("SSN")
	next
elseif len(rs("SSN") ) = 0 Then
	rs("SSN") = "122121212"
End If
rs("Import Date") = Now()
rs("Name")='" & Trim(Replace(rs("Name"), "*", " ")) "',"
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: MLG0001
Solution Provided By: acperkins
Participating Experts: 2
Solution Grade: A
Views: 169
Translate:
Loading Advertisement...
02.21.2008 at 03:23PM PST, ID: 20952960

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 07:55AM PST, ID: 20958494

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 08:07AM PST, ID: 20958642

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 08:13AM PST, ID: 20958718

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 08:21AM PST, ID: 20958831

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 09:56AM PST, ID: 20959696

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 10:06AM PST, ID: 20959791

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 10:12AM PST, ID: 20959839

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 10:20AM PST, ID: 20959906

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.22.2008 at 10:24AM PST, ID: 20959928

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.21.2008 at 03:23PM PST, ID: 20952960
You can use

Connection.Execute "UPDATE ...."

 
02.22.2008 at 07:55AM PST, ID: 20958494

Rank: Wizard

>>I'm attempting to update existing records that are already in a SQL database through an Active X Script in SQL using VBScript. <<
Why?  All you need is a simple update statement.  No need to loop through all the rows.  That would be slow as molasses.
 
02.22.2008 at 08:07AM PST, ID: 20958642

Rank: Wizard

Just add an Execute SQL Task to your DTS Package with this UPDATE statement and appropriate workflow:
UPDATE      YourTableName
Set       SSN =      CASE
                  WHEN SSN Is Null Or LEN(SSN) = 0 THEN '122121212'
                  ELSE RIGHT(REPLICATE('0', 9) + SSN, 9)      -- Covers the case when the length is 1 through 8
            END,

      [Import Date] = GETDATE(),
      Name = LTRIM(RTRIM(REPLACE(Name, '*', ' ')))
WHERE      LEN(IsNull(SSN, '')) < 9
 
02.22.2008 at 08:13AM PST, ID: 20958718
The Execute "UPDATE...." statement only works when the values are constant. i.e. [import date] = Now(), [Record Processed] =1.

The values are originating from a daily excel file that is imported into the database. I want to validate the values in columns to make sure that they are in the correct format.
I need to look at length of existing values in the database and update accordingly. For example, if the agent field has len < 10 then I must add leading zeros to the value that is in the database. Don't I have to open the recordset first to be able to see the existing values  and loop through each to determine if the field needs updated?
 
02.22.2008 at 08:21AM PST, ID: 20958831

Rank: Wizard

>>Don't I have to open the recordset first to be able to see the existing values  and loop through each to determine if the field needs updated?<<
Only if you are into pain.
 
02.22.2008 at 09:56AM PST, ID: 20959696
THANK YOU THANK YOU THANK YOU - This worked great!...One more need for this update statemetn..If the Agent Code is 1004 then the Gift Card amount needs to be 100, or if its 1005, then the gift card amt is 1000...How do I use a case that will check 2 different field values?
--[AGENT CODE] = CASE
--WHEN [AGENT CODE] = '1004' THEN
--[GIFT CARD AMT] = '100'
--END
 
02.22.2008 at 10:06AM PST, ID: 20959791
UPDATE titles
       SET [GIFT CARD AMT]=
                 CASE
                   WHEN ([AGENT CODE] = 1004)
                                   THEN 100
                   WHEN ([AGENT CODE] = 1005)
                                   THEN 1000
                   END

Hope it helps

Detailed example below
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
UPDATE titles
       SET price =
                 CASE
                   WHEN (price < 5.0 AND ytd_sales > 999.99)
                                   THEN price * 1.25
                   WHEN (price < 5.0 AND ytd_sales < 1000.00)
                                   THEN price * 1.15
                   WHEN (price > 4.99 AND ytd_sales > 999.99)
                                   THEN price * 1.2
                   ELSE price
                 END 
Open in New Window
Assisted Solution
 
02.22.2008 at 10:12AM PST, ID: 20959839

Rank: Wizard

UPDATE      YourTableName
Set      SSN =      CASE
                  WHEN SSN Is Null Or LEN(SSN) = 0 THEN '122121212'
                  ELSE RIGHT(REPLICATE('0', 9) + SSN, 9)      -- Covers the case when the length is 1 through 8
            END,
      [Import Date] = GETDATE(),
      Name = LTRIM(RTRIM(REPLACE(Name, '*', ' '))),
      [GIFT CARD AMT] =
            CASE [AGENT CODE]
                  WHEN  '1004' THEN 100
                  WHEN '1005' THEN 1000
                  ELSE [GIFT CARD AMT]      -- Not 1004 or 1005, so it stays the same?
            END
WHERE      LEN(IsNull(SSN, '')) < 9
 
02.22.2008 at 10:20AM PST, ID: 20959906

Rank: Wizard

Just a word of caution if you use vs1784 suggestion make sure you add an ELSE clause to the CASE statement, otherwise if the agent code is neither 1004 or 1005 than the Gift Card Amt will be set to Null.
 
02.22.2008 at 10:24AM PST, ID: 20959928

Rank: Wizard

I should have added, there are three possible outcomes to setting the Gift Card Amt to Null:
1. The table does not allow it, in which case the UPDATE statement will fail.
2. It is not what you need.
3. It is what you desire.

Even if it is case 3, I would urge you to do it this way so that it is obvious:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
UPDATE	YourTableName
Set	SSN =   CASE
			WHEN SSN Is Null Or LEN(SSN) = 0 THEN '122121212'
			ELSE RIGHT(REPLICATE('0', 9) + SSN, 9)      -- Covers the case when the length is 1 through 8
		END,
	[Import Date] = GETDATE(),
	Name = LTRIM(RTRIM(REPLACE(Name, '*', ' '))),
	[GIFT CARD AMT] = 
			CASE [AGENT CODE]
				WHEN  '1004' THEN 100
				WHEN '1005' THEN 1000
				ELSE NULL 		--Explicitly set to Null
			END
WHERE	LEN(IsNull(SSN, '')) < 9
Open in New Window
Accepted Solution
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628