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)
 Covert claim no to bigint, plus 1

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-10-22 : 10:30:01
I need to convert ClaimNum (nvarchar) such as 200910258570002 to bigint, plus 1 and convert to nvarchar again.
How to code it in a store procedure?

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-22 : 10:36:28
select cast(cast('200910258570002' as bigint)+1 as nvarchar)

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-10-22 : 11:04:39
I used code below but do not work as expected.
test data: A.CLAIMNO = 200910228450002, nvarchar data type

declare @c bigint
set @c = cast((select distinct A.CLAIMNO from a) as bigint)+1
print @c // print out as 200910228450003 that is correct
declare @d nvarchar
set @d = cast(@c as nvarchar(50))
print @d //print out as 2, not correct, should be 200910228450003

How to code to make @d = 200910228450003 as nvarchar type?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-22 : 11:08:29
quote:
Originally posted by Sun Foster

I used code below but do not work as expected.
test data: A.CLAIMNO = 200910228450002, nvarchar data type

declare @c bigint
set @c = cast((select distinct A.CLAIMNO from a) as bigint)+1
print @c // print out as 200910228450003 that is correct
declare @d nvarchar
set @d = cast(@c as nvarchar(50))
print @d //print out as 2, not correct, should be 200910228450003

How to code to make @d = 200910228450003 as nvarchar type?


You should have size for nvarchar datatype

declare @d nvarchar

should be

declare @d nvarchar(50)

Madhivanan

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

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-10-22 : 11:12:06
Thank you, madhivanan. It is working now.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-23 : 01:53:07
quote:
Originally posted by Sun Foster

Thank you, madhivanan. It is working now.


You are welcome

Madhivanan

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

- Advertisement -