?
Solved

SQL array function

Posted on 2014-12-31
8
Medium Priority
?
195 Views
Last Modified: 2014-12-31
Hello,

Within vb script, I have a function that adds a record to a SQL table and it works fine.


      rst.Open "Select * FROM BW_AUFTR_KTXT", oADOConn, adOpenKeyset, adLockBatchOptimistic, adCmdText
      rst.AddNew Array("ID", "LFD_NR", "TEXT_ID", "DRUCK_KZ", "MOD", "BEZ"), Array(Item.UserProperties("CSIOrderNo1").value, "45", "45", "X", "0", "LIFT GATE REQUEST")
      rst.Update


Is it possible to select all the fields and update them without calling out the field names. For example:

      rst.Open "Select * FROM BW_AUFTR_KTXT", oADOConn, adOpenKeyset, adLockBatchOptimistic, adCmdText
      rst.AddNew Array(test1,test2,test3)
      rst.Update

Thanks, Joel
0
Comment
Question by:Genius123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 79

Expert Comment

by:arnold
ID: 40525948
The only time you can is when you include all columns in the correct order
If you use a cursor to go through your response, in defining the cursor you can specify which columns are updateable.

I am unclear what it is you are doing, it seems less as an update and more as though you are overwriting the contents of response without seemingly a reason.
0
 

Author Comment

by:Genius123
ID: 40526076
Thanks for your response.  What I am trying to do is create a record with a set of known values.  So lets say the table fields are as such:

ID (autonumber)
East
West
North
South

I will create a record and just assign the same values each time like:

ID (autonumber)
East = 1
West = 2
North  = 3
South = 4

I know this might not make sense, but I'm just giving a simple example.  The table actually has about 100 fields.

Thanks.
0
 
LVL 79

Expert Comment

by:arnold
ID: 40526097
You have to make sure the table column definitions allow nulls, you would then specify the columns to which the data you are adding will correspond the remaining cells will eighter be the default or null depending on your table definition.

Note that you should not include the Id(autonumber)
rst.AddNew Array("ID","LFD_NR", "TEXT_ID", "DRUCK_KZ", "MOD", "BEZ"), Array(Item.UserProperties("CSIOrderNo1").value, "45", "45", "X", "0", "LIFT GATE REQUEST")
      rst.Update

Open in new window


The order of the declared columns is how the values you are adding are referenced.

A table of 100 columns begs for normalization into sub tables.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Genius123
ID: 40526100
Can you do something like this?

rst.AddNew Array(*), Array(1,2,3,4)
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40526131
As an aside, instead of a SELECT * recordset is there any chance you can create an UPDATE statement, then execute that as a command?  That would save you the overhead of loading the entire recordset.
0
 
LVL 79

Accepted Solution

by:
arnold earned 2000 total points
ID: 40526132
No, there is no way to which columns the 1,2,3,4 belong.
you have to define the columns
rst.AddNew Array ("East","West","North","South"), Array(1,2,3,4)

The other way is to use the fields properies to set the column and assign the value.
0
 

Author Closing Comment

by:Genius123
ID: 40526135
Thanks for the help.  I putting down that the solution is that there is no solution to my question.
0
 
LVL 79

Expert Comment

by:arnold
ID: 40526147
Depending on what you trying to do, there are different more efficient ways to load data.

If the answer does not answer you might want to rephrase it to have others look at it and see whether there is a different way to achieve what you want.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question