VB sql statement

C

cj

I have a table with 3 fields (field1 is text, field2 and field3 are int)
I want to write a sql command for VB that will return field1 and the sum
of field2 and field3. For instance if the table had two rows

Ted 4 7
Fred 5 8

the dataset returned would be

Ted 11
Fred 13

Can someone give me a statement to do this?
 
L

Lloyd Sheen

cj said:
I have a table with 3 fields (field1 is text, field2 and field3 are int)
I want to write a sql command for VB that will return field1 and the sum
of field2 and field3. For instance if the table had two rows

Ted 4 7
Fred 5 8

the dataset returned would be

Ted 11
Fred 13

Can someone give me a statement to do this?

select field1 , field2 + field3 from table

LS
 
C

cj

I tried that earlier and it didn't work. Well that's confusing now it
does. what the heck?
 
S

Steven Cheng [MSFT]

Hi Cj,

Does the table columns(you want to sum) be set to the correct number type
previously or maybe the original SQL script contains some syntax error?
Anyway, a quick way to verify it is execute it in QueryAnzlayer or
Management studio to see whethe the result is expected.

BTW, just for your information, ADO.NET dataset/datatable also support
computed column. But I think generated the value at database/sql side is
more effecient:

#Creating Computed Columns in a DataSet
http://www.objectsharp.com/cs/blogs/datasetfaq/archive/2004/05/20/466.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
C

Cor Ligthert[MVP]

CJ,

As it is about VB SQL code, do you mean something as Linq.

There is no VB SQL code, although some people mean with this too
Expressions.

For the rest I don't know VB SQL code.

Will you please tell us where this is about?

Cor
 
C

cj

Thanks Steven, I'm not sure what I did wrong when I tried it the first
time. I must have done something. I was testing sql commands in SQL
Query Analyzer with the intent of using them in VB when I got them
working. I quickly assumed field2+field3 was not allowed in sql and
decided to ask how it was done. When Lloyd wrote his response I was
puzzled but decided to try it again before I told him it didn't work. I
was surprised when it worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top