Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
i have a field time_of_arrival there i am capturing hour and minutes the field name is fldarrival
(i.e)
08-44
8-45
10-5
10-05
 
Here i am writing query to split hour and minutes here only i am getting confusion. my query is :
select substring(fldarrival,1,2) as HH from dbo.CS_Initial_Assessment
select substring(fldarrival,3,2) as HH from dbo.CS_Initial_Assessment

my output is
HH  MM
08  44
8-  45
10  -5
10  05
 
Expected output:
HH  MM
08  44
 8  5
10  5
10  05
Here i want to remove special character. Can any one pls suggest how to go about it.
 
Regards,
Vinoth
Posted 8-Feb-13 23:15pm
Edited 11-Feb-13 2:29am
Maciej Los158.8K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use REPLACE[^] instead of SUBSTRING:
SELECT REPLACE(fldarrival, '-', ' ') as HH FROM dbo.CS_Initial_Assessment
  Permalink  
Comments
Maciej Los at 11-Feb-13 7:30am
   
Short and to the point, +5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use replace function
 
eg.
select replace('08- 45','-','')
 
Happy Coding!
Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100