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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Column addition

Author  Topic 

infodemers
Posting Yak Master

183 Posts

Posted - 2008-10-29 : 10:59:47
Hi

I try To add the columns D + E + F and display the result in column C
I run this update query to do it.

UPDATE Table_Name
SET C = isnull([D],0) + isnull([E],0) + isnull([F],0)
Where = 'GWC'

I get that little * as result, Any idea?

[b] A B C D E F
ABCDEF GWC * 553 371 0
GHIJKL GWC * 381 375 0
MNOPQR GWC * 358 482 0
STUVWX GWC * 14 70 0


Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 11:22:49
what are the datatypes of C,D,E & F?
Go to Top of Page

infodemers
Posting Yak Master

183 Posts

Posted - 2008-10-29 : 11:28:32
The datatypes are all Integer
quote:
Originally posted by visakh16

what are the datatypes of C,D,E & F?

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 11:35:07
i dont think so. seems like C is varchar or char
Go to Top of Page

infodemers
Posting Yak Master

183 Posts

Posted - 2008-10-29 : 11:42:10
You are probably right, because my table is a temporary one.
Should I convert the data fisrt before the addtion then?
quote:
Originally posted by visakh16

i dont think so. seems like C is varchar or char

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 12:10:02
can you post the structure of your table? you need to make sure C is of integer type if D,E,F are all integer
Go to Top of Page

infodemers
Posting Yak Master

183 Posts

Posted - 2008-10-29 : 12:24:45
My table is a temporary table and doesn't have any structure.
To make sure the data types are okay, then I should create the temporary table and specify the type, right?

UPDATE #Table_Name
SET C = isnull([D],0) + isnull([E],0) + isnull([F],0)
Where = 'GWC'

quote:
Originally posted by visakh16

can you post the structure of your table? you need to make sure C is of integer type if D,E,F are all integer

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 12:29:24
yup you should like below

CREATE TABLE #Table_name
(
..
C int,
D int,
E int,
F int,
....
)
Go to Top of Page

infodemers
Posting Yak Master

183 Posts

Posted - 2008-10-29 : 12:39:47
Give the man a cigar!
Do you know if in SQL 2005 we also need to do the same?

Thanks for your help!

quote:
Originally posted by visakh16

yup you should like below

CREATE TABLE #Table_name
(
..
C int,
D int,
E int,
F int,
....
)


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 12:47:52
quote:
Originally posted by infodemers

Give the man a cigar!
Do you know if in SQL 2005 we also need to do the same?

Thanks for your help!

quote:
Originally posted by visakh16

yup you should like below

CREATE TABLE #Table_name
(
..
C int,
D int,
E int,
F int,
....
)





yup..its same with sql 2005 also
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-30 : 04:12:25
See why you get *

declare @d varchar(3)
set @d=123*600
print @d

Madhivanan

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

- Advertisement -