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)
 get max value

Author  Topic 

gaauspawcscwcj
Starting Member

29 Posts

Posted - 2009-10-28 : 22:01:21
hi all

i have table with definition like below
table :
name varchar(10)
series varchar(40)

data :
name series
a 1
b 2
c 3
d 1000000000000000000000000000000000000000

--> the requirment is if i insert one more record so series field is increase one more than max value of series in table.
--> i have to get max value of series and plus with 1 but data type of bigint is 8 bit and decimal is 18 --> i counld not get max value of series if data of series get to 40 digits.
any ideas for helping me
thanks alot

gaauspawcscwcj

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-28 : 23:09:03
Refer to http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/sql-server-fibonacci-sequence

there is a AddString() there


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

gaauspawcscwcj
Starting Member

29 Posts

Posted - 2009-10-28 : 23:32:11
hi khtan
i dont understand much.
all i want is get max value.
function FUNCTION dbo.AddString(@String1 VARCHAR(8000), @String2 VARCHAR(8000)) must be add 2 value String1 ,String2
in my case what value of String1 and String2 that i need.
thanks

gaauspawcscwcj
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-28 : 23:35:08
you can't convert a 40 digits long number in string to decimal or bigint. It is not big enough. You have to use a user defined function to perform the addition and you can use the function i posted in that link.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

gaauspawcscwcj
Starting Member

29 Posts

Posted - 2009-10-29 : 00:02:49
i ve just run dbo.AddString(@String1 VARCHAR(8000), @String2 VARCHAR(8000)) base on your link but the result is not expected.
the result is
0
1
1
2
3
5
8
13
...
61305790721611591
99194853094755497

--> expected result is :
0
1
2
3
4
5
6
...
61305790721611591
61305790721611592

gaauspawcscwcj
Go to Top of Page
   

- Advertisement -