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)
 Problem in calculation

Author  Topic 

binuj
Starting Member

5 Posts

Posted - 2008-11-06 : 05:11:58
Hi,

My records:

12~456
1~345
23~567
34~333
3~444

I need to extract the first 2 digits and do some calculation. I extracted by using the Substring function. now the problem is the nvarchar character (~) is giving error when doing some calculation.

Please help me in this. How will i extract teh digit without (~) character.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-06 : 05:17:18
[code]DECLARE @Sample TABLE
(
data VARCHAR(20)
)

INSERT @Sample
SELECT '12~456' UNION ALL
SELECT '1~345' UNION ALL
SELECT '23~567' UNION ALL
SELECT '34~333' UNION ALL
SELECT '3~444'

SELECT data,
PARSENAME(REPLACE(data, '~', '.'), 2),
PARSENAME(REPLACE(data, '~', '.'), 1)
FROM @Sample[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

binuj
Starting Member

5 Posts

Posted - 2008-11-06 : 06:13:39
Thanks a ton.......it is working fine.....

the best forum for SQL Server

MAY GOD BLESS YOU ALL
Go to Top of Page
   

- Advertisement -