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 Los175.5K
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 Suvendu Shekhar Giri 265
1 Sergey Alexandrovich Kryukov 260
2 Andy Lanng 185
3 PIEBALDconsult 180
4 OriginalGriff 130
0 Sergey Alexandrovich Kryukov 6,425
1 OriginalGriff 5,918
2 Peter Leow 2,514
3 Maciej Los 2,263
4 Abhinav S 2,249


Advertise | Privacy | Mobile
Web01 | 2.8.150414.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