Click here to Skip to main content
11,479,162 members (63,370 online)
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 Los182.3K
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 Sergey Alexandrovich Kryukov 205
1 F-ES Sitecore 195
2 OriginalGriff 130
3 Frankie-C 120
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,366
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2015
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