473,671 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Build SQL string looping through field names

I need to build an UPDATE statement that copies the values of roughly 40
fields from a table that stores standard or default values into a table of
specific contracts. There are 8 or so fields in the source table that are
not in the destination table. The remaining field names are identical in
both tables. How do I create a recordset of the field names I am interested
in so that I can loop through it to build my UPDATE statement?

Thank you
Jul 22 '05 #1
3 2874
WC Justice wrote:
I need to build an UPDATE statement that copies the values of roughly
40 fields from a table
Oops - you forgot to tell us what type and version of database you are
using. I Suspect Access, but it would be nice to be sure.
that stores standard or default values into a
table of specific contracts.
Simple answer:

Don't

Don't store the same data twice. You are likely to be using a relational
database here. By storing te same data twice, you are interfering with the
ability of the rdbms to preserve data integrity.

Instead of copying all these values to a separate table, store a link to the
standard values.

The only reason not to do this is if you need to track historicity, i.e.,
you need to know what the values were at the time the record was created.
But even this can be done without copying the data by using EffectiveDate
and DiscontinueDate columns in the standards table.
There are 8 or so fields in the source
table that are not in the destination table. The remaining field
names are identical in both tables. How do I create a recordset of
the field names I am interested in so that I can loop through it to
build my UPDATE statement?


If you're bound and determined, then you have a few options, which you can
read about here:http://www.aspfaq.com/show.asp?id=2177, although he did
leave out the OpenSchema option which you can read about here:
http://msdn.microsoft.com/library/en...openschema.asp
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #2
Thanks for the response. This is an ASP-based website with a Microsoft 2003
Windows Small Business Server SQL Server back end.

I respect your advice regarding duplicating of records, however it is
necessary in this case. Each contract contains these 40 provisions which
need to be editable at the contract level. When the user indicates that he
wants to create a new contract, one of the subroutines attaches the default
provisions to the new contract, which are then edited as necessary or
appropriate. I started hard coding the SQL string but was hoping to avoid
doing it for both the INSERT and UPDATE statements.

A scan of the links you provided makes me feel that it may be a little over
my head, but if you think it will address my question, I will study it until
I get it.

Thanks again.

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
WC Justice wrote:
I need to build an UPDATE statement that copies the values of roughly
40 fields from a table
Oops - you forgot to tell us what type and version of database you are
using. I Suspect Access, but it would be nice to be sure.
that stores standard or default values into a
table of specific contracts.


Simple answer:

Don't

Don't store the same data twice. You are likely to be using a relational
database here. By storing te same data twice, you are interfering with the
ability of the rdbms to preserve data integrity.

Instead of copying all these values to a separate table, store a link to

the standard values.

The only reason not to do this is if you need to track historicity, i.e.,
you need to know what the values were at the time the record was created.
But even this can be done without copying the data by using EffectiveDate
and DiscontinueDate columns in the standards table.
There are 8 or so fields in the source
table that are not in the destination table. The remaining field
names are identical in both tables. How do I create a recordset of
the field names I am interested in so that I can loop through it to
build my UPDATE statement?


If you're bound and determined, then you have a few options, which you can
read about here:http://www.aspfaq.com/show.asp?id=2177, although he did
leave out the OpenSchema option which you can read about here:
http://msdn.microsoft.com/library/en...openschema.asp
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #3
WC Justice wrote:
Thanks for the response. This is an ASP-based website with a
Microsoft 2003 Windows Small Business Server SQL Server back end.

I respect your advice regarding duplicating of records, however it is
necessary in this case. Each contract contains these 40 provisions
which need to be editable at the contract level. When the user
indicates that he wants to create a new contract, one of the
subroutines attaches the default provisions to the new contract,
which are then edited as necessary or appropriate.
Why insert them at this point? Why not simply retrieve the values and
present them to the user in the editing page? Then, when he saves his edits,
write the final version of the contract into the database. Just a
suggestion.
I started hard
coding the SQL string but was hoping to avoid doing it for both the
INSERT and UPDATE statements.
I would hard-code it anyways. You can use QA (if you have it) to generate
the list of columns using one of the techniques in the aspfaq article.

A scan of the links you provided makes me feel that it may be a
little over my head, but if you think it will address my question, I
will study it until I get it.


Start studying :-)

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5598
by: Rob Young | last post by:
This is the latest in the "Total Non-Programmer" series. Any feedback on the usability of this tutorial would be greatly appreciated. Thanks, Rob How to Build A Web Database (Without Programming) This article will teach you step-by-step how to add interactive database-driven capabilities to your existing web site. When the steps
10
2325
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a similar name to the table. Rather than making a long Select Case that could become obsolete if lookup tables are added and the source table of the ListBox is edited I came up with this code.) This code works but of course it gives me build...
6
2153
by: H | last post by:
This is a question that has haunted me for quite some time. if you build a 4 tier database application where the 4th tier is the database server (MS SQL 2000), where do you build the connection string? The obvious answer is to hard code it into the middle layer and use a config file. The problem is the database application needs to be distributed to purchasing clients. Therefore, you do not know, at development, what the SQL
2
1872
by: Soundneedle | last post by:
I have code that loops through a record set, which build an outlook email's body. The problem is, I don't know how to "build" the .body while in the loop without resetting the .body's value to the current record. For example, the .body should equal: John Jake Debby
17
4654
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some analysis and I'm led to believe (but can't yet quantitatively establish as fact) that the two basic culprits are a lot of calls to: 1.) if( someString.ToLower() == "somestring" ) and
9
10518
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient: objMailMessage.To = dtrRecipient; I'm not sure why I am getting this error. Below is the complete code I am working with.
2
1565
by: Tamarack | last post by:
I have a simple function which loops through all the controls on a form searching for a specific one: Public Function FindControl(ByVal ctrls As Control.ControlCollection, ByVal ctrlName As String) As Control For Each ctrl As Control In ctrls If ctrl.Name = ctrlName.Trim Then Return ctrl End If
4
2281
by: BA | last post by:
Hello, I have a very strange code behavior that I cannot make heads or tails of: I have c# code being executed in BizTalk assemblies which is acting very strangely. In my BizTalk process I call a static method: public static string ValidateMessage(params...)
3
6800
by: N L | last post by:
Greetings, I want to create a form in Access that shows a list of checkboxes to a user. The checkboxes will be dynamically generated, showing the fields in a table the user has selected in a combo box. Can anyone tell me how to dynamically update a list of checkboxes like that? Thanks,
0
8473
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.