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
 Transact-SQL (2000)
 converting data ....as 'value' always varchar?

Author  Topic 

dirwin26
Yak Posting Veteran

81 Posts

Posted - 2005-11-01 : 12:38:56
How can I divide two fields found within the same column. I tried the below proc. but i can't convert the 'AA' and 'BB' to a number type. Is the default for these variables varchar? Why won't my convert statements change these two values to bigint?

SELECT TOTALCAP1 AS 'AA'
FROM CASHBALANCE
WHERE THEDAY = @THEDATE


SELECT TOTALCAP1 AS 'BB'
FROM CASHBALANCE
WHERE THEDAY = @DATE1

select (convert(bigint,'AA')/convert(bigint,'BB')) as 'rtn'

Error converting data type varchar to bigint.

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-11-01 : 12:45:32
[code]

DECLARE @CAP1 as DECIMAL
DECLARE @CAP2 as DECIMAL


SELECT @CAP1 = SUM(TOTALCAP1)
FROM CASHBALANCE
WHERE THEDAY = @THEDATE


SELECT @CAP2 = SUM(TOTALCAP1)
FROM CASHBALANCE
WHERE THEDAY = @DATE1


SELECT @CAP1 / @CAP2
[/code]

Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page

dirwin26
Yak Posting Veteran

81 Posts

Posted - 2005-11-01 : 15:02:19
It worked perfectly.

Cheers,
Dirwin
Go to Top of Page
   

- Advertisement -