Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding numeric values in the database

Author  Topic 

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-11 : 08:57:28
hi folks...now m in serious trouble...i hve a very complicated problem now...

let me explain

i have a table in SQL...I have to select values from this table depending on 2 where conditions.....and add these values......and insert them in another table......

now can somebody tell me how can i add the values from the database and store them in a session and update them to another table...

if i am not clear then ask me i will explain u in more detail


Navi

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-11 : 08:59:34
I am confused? do you want to insert new record in another table with added value or update table with new value?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-11 : 09:10:13
INSERT TargetTable (Col1)
SELECT ColA + ColB
FROM SourceTable
WHERE ColBlue = 'SQLTeam' AND ColGreen = 'Peso'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-11 : 09:14:32
quote:
Originally posted by Peso

INSERT TargetTable (Col1)
SELECT ColA + ColB
FROM SourceTable
WHERE ColBlue = 'SQLTeam' AND ColGreen = 'Peso'



E 12°55'05.25"
N 56°04'39.16"



OP, Beware of NULL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-11 : 09:17:14
Me? I think you need to tell OP that.
He didn't provide enough information.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-11 : 09:19:43
quote:
Originally posted by Peso

Me? I think you need to tell OP that.
He didn't provide enough information.


E 12°55'05.25"
N 56°04'39.16"



Its to OP. I edited my reply

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-12 : 04:54:28
i dont have to add the clumns. i have to add the rows....wat do i do?


Navi
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-12 : 05:51:44
No idea what you are talking about.

Can you post some proper and accurate sample data together with your expected result?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-12 : 07:03:52
Use aggregate functions like SUM() to add up row values.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-12-12 : 09:41:02
could have swornd that SUM() added up column values....

SUM
Returns the sum of all the values, or only the DISTINCT values, in the expression.
SUM can be used with numeric columns only. Null values are ignored.



[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

feejaz
Yak Posting Veteran

68 Posts

Posted - 2007-12-15 : 07:53:36
i have a table in the below shown format

Values Items.......................................................TABLE1

Customer1 20 Fuses

Customer2 30 Screws

Customer3 40 Fuses

Customer1 45 Fuses

Customer3 78 Batteries

Customer1 40 Screws

now i want to add the values of screw of customer1 and insert in a table in one field as shown below

Screws Fuses Screws .................................TABLE2

there is the example of my question

Customer1 65 (total of above) 115 40

Custoerm2 ------------------------------------

NOW ADD VALUES IN THE ABOVE WAY AND INSERT IN THE TABLE 2


Navi
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-15 : 09:12:09
Read about Cross-tab reports in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -