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 2005 Forums
 Transact-SQL (2005)
 large value in varchar(max) field...

Author  Topic 

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2008-11-06 : 10:04:51
Hi There

I have an sp which puts all of the max values of fields in a table into another table. (with Max_value field datatype varchar(max))

Now when I view the max values of say large float fields i.e. Amount
I will see 1.1904e+008, but when I copy & paste this value into Excel and change the column type to Text then I get the full value i.e.: 119040000

Can anybody tell me how I would store this value 11904000 as it is in my SQL table?

Thanks!!

p.s The max values (irrespective of the datatype) need to be stored in one column of another table which has datatype varchar(max)



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-06 : 10:06:37
try casting the flaot values to decimal or numeric with maximum precision you want before appending to variable.
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2008-11-06 : 10:29:33
Hmm... the issue is that I would need to know the datatype of the field which I'm trying to find the max value for, now my procedure will loop through each field (without me knowing the datatype)




Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-06 : 10:33:01
actually what's the purpose behind creating this varchar(max) column with all variables?
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2008-11-06 : 10:44:46
My purpose is to quickly identify all the min/max values of all fields in a table. Just to give me a picture of the range of values within the table.

I'm not sure what datatype I can use to store all the MAX values of different variations of datatypes of fields.

i.e. my Max_Value table could look something like this:

Column_Name, Max_Value
Name , ZXY Ltd
Start , 1990-01-01
Employees , 99999
Turnover , 9999999999999
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-06 : 11:00:00
but why store it like this? you can always use MAX() function in select and retrive them in your selects. Any special reason for storing each column along with max value?
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2008-11-06 : 11:11:55
The table (audit_Table) which stores all the values is created first, and then a procedure will loop through each field in the table take it's max value per field and insert into this Audit_Table. Hence I will need a datatype which will be able to store all the max values from the loop from each field.


(Hope that makes sense!)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-06 : 11:18:12
If anyways you're going to put max values of all columns into audit_table, why dont put it horizontally as a single row with all columns(that way audit_table will have exact structure of your main table)
Go to Top of Page

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-11-06 : 11:25:27
before convert it to VARCHAR(MAX) convert your FLOAT data type to DECIMAL

select cast(cast(<float_field> as decimal) as varchar(max))
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-06 : 11:28:03
quote:
Originally posted by hanbingl

before convert it to VARCHAR(MAX) convert your FLOAT data type to DECIMAL

select cast(cast(<float_field> as decimal) as varchar(max))


that was what i suggested in my first reply.But seems like OPs column datatypes will be determined only at runtime.
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2008-11-06 : 12:09:51
Hi I've tried cast as varchar(max), but still no luck....

It's fine if I just run the select statement, but when i insert into my table it displays 1.1904e+008
Go to Top of Page

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-11-06 : 13:43:38
like visakh16 said, why not make the audit table the same structure as your data table:

you can then get all the max values with 1 sql statement:

select max(col1), max(col2), max(col3), max(col4)... from <table>
Go to Top of Page
   

- Advertisement -