473,408 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Add data for unknown name columns

3
I have a table with a lot of columns (and I don't know exactly names of these columns). How can I add data (data is calculated via function) for these columns using only index_col?
Jan 17 '08 #1
6 1843
Delerna
1,134 Expert 1GB
Don't understand how you can know the index of the columns you want to calculate and not be able to find out what its name is, but anyway.

You can't with in SQL server as far as I am aware
You can SELECT * FROM TableName but you need to know the field names to perform calculations

You could do it with a scripting language connecting the various data objects
to your SQL server
and executing SELECT * FROM TableName query into a recordset object

then you can use things like
Variable=rst.fields(5)-rst.fields(7)
where rst is the recordset object with the retrieved data

Does that help???
Jan 17 '08 #2
UtLinh
3
Don't understand how you can know the index of the columns you want to calculate and not be able to find out what its name is, but anyway.

You can't with in SQL server as far as I am aware
You can SELECT * FROM TableName but you need to know the field names to perform calculations

You could do it with a scripting language connecting the various data objects
to your SQL server
and executing SELECT * FROM TableName query into a recordset object

then you can use things like
Variable=rst.fields(5)-rst.fields(7)
where rst is the recordset object with the retrieved data

Does that help???
I said incorrectly. In fact I want to use column_id
My detail task is:
+ I have table T1 with columns: c1, c2, c3, c4, c5, ..., cN.
+ c1, c2 have some data.
+ I need to calculate c3 = func(c1, c2, 'c3'), c4 = func(c1, c2, 'c4') ...

If I know name of c4 (for example: nameC4), then I can write
update T1
set T1.nameC4 = func(c1, c2, 'nameC4')

It was good if I could write:
update T1
set T1.[col_name(T1_id, 4)] = func(c1, c2, col_name(T1_id, 4))

because in the example c4 has col_id = 4. And in all cases I need to add data for all of columns except c1, c2 (I've known their col_id = 1, 2)
But write as I wanted is incorrect.

If it's your task how will you do?
Thanks for your attention
Jan 17 '08 #3
ck9663
2,878 Expert 2GB
I said incorrectly. In fact I want to use column_id
My detail task is:
+ I have table T1 with columns: c1, c2, c3, c4, c5, ..., cN.
+ c1, c2 have some data.
+ I need to calculate c3 = func(c1, c2, 'c3'), c4 = func(c1, c2, 'c4') ...

If I know name of c4 (for example: nameC4), then I can write
update T1
set T1.nameC4 = func(c1, c2, 'nameC4')

It was good if I could write:
update T1
set T1.[col_name(T1_id, 4)] = func(c1, c2, col_name(T1_id, 4))

because in the example c4 has col_id = 4. And in all cases I need to add data for all of columns except c1, c2 (I've known their col_id = 1, 2)
But write as I wanted is incorrect.

If it's your task how will you do?
Thanks for your attention
if you don't really know the name of the column, how would you know you're using the right column? are you basing it in position?

-- CK
Jan 17 '08 #4
Delerna
1,134 Expert 1GB
OK
+ I have table T1 with columns: c1, c2, c3, c4, c5, ..., cN.
+ c1, c2 have some data.
+ I need to calculate c3 = func(c1, c2, 'c3'), c4 = func(c1, c2, 'c4') ...

Not completely understanding what you mean by c3 = func(c1, c2, 'c3')
What is the calculation the func is carrying out and why is c3 in the parameters???

Anyway I think you are trying to update c3,c4,c5,....,cn in table t1 with a calculation based on C1 and C2.....is that correct???

Here is query to do above
Update T1 set C3=C1+C2,C4=C2/C1,.... etc
Where FieldName=Condition

the Where clause is optional if you only want to affect certain rows


I may be way off what you are after here but I hope it helps
Jan 17 '08 #5
UtLinh
3
OK
+ I have table T1 with columns: c1, c2, c3, c4, c5, ..., cN.
+ c1, c2 have some data.
+ I need to calculate c3 = func(c1, c2, 'c3'), c4 = func(c1, c2, 'c4') ...

Not completely understanding what you mean by c3 = func(c1, c2, 'c3')
What is the calculation the func is carrying out and why is c3 in the parameters???

Anyway I think you are trying to update c3,c4,c5,....,cn in table t1 with a calculation based on C1 and C2.....is that correct???

Here is query to do above
Update T1 set C3=C1+C2,C4=C2/C1,.... etc
Where FieldName=Condition

the Where clause is optional if you only want to affect certain rows


I may be way off what you are after here but I hope it helps
My function funct(c1,c2, 'c3') is:

select count(...)
from TableX
where TableX.v1 = c1 and TableX.v2 = c2 and TableX.v3 = 'c3'
// I use column-name as value


See your query:

Update T1 set C3=C1+C2,C4=C2/C1,.... etc
Where FieldName=Condition

+ Your query will be used only if we know column-name C3
+ I need to update all columns, not one c3.
Jan 21 '08 #6
Delerna
1,134 Expert 1GB
Oh, are you trying to pass the name of the field to be updated to the function???

So you can say to the function "Update This field"
now "Update this other field"
etc
If so youre talking dynamic sql
Jan 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
7
by: Ivan Debono | last post by:
Hi, I keep getting an Unknown runtime error on line 3 below: 1 If oField.Type <> 136 Then 'adChapter 2 If Right(oField.name, 3) = "_id" Then 3 For Each...
5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
1
by: BStrick | last post by:
I would like to know what may be the "Best" way to approach with problem. I have an application that I created to transfers data dynamically from an unknown source (ie maybe Excel, Access, XML,...
9
by: Ben R. | last post by:
Hi guys, I've got a DB table of timecards with these fields in the table: ID (Int) UserID (Int) DateWorked (DateTime) HoursWorkedOnThatDate (Double) I'd like to display a grid, with...
0
by: dba123 | last post by:
I am getting the following error when a sub domain is receiving a shared cookie: I have this in both web.config of each application. The 1.1 application does not have the decryption= value...
3
by: Izzy | last post by:
Here is the code. Dim conExcel As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ExcelPath & ";Extended Properties=""Excel 8.0;HDR=NO;""" Dim cmdOLE As OleDb.OleDbCommand Dim conOLE...
4
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.