Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to convert string to int but '/' should be escaped.
I'm trying :
SQL
select [R-Date] from Reg where (CONVERT(INT,Reg.[R-Date] ESCAPE'/') BETWEEN 13920201 AND 13920222


but I get error :
SQL
Incorrect syntax near the keyword 'ESCAPE'.


and when I remove escape '/' I get:
Conversion failed when converting the nvarchar value '1392/02/11' to data type int.
Posted
Updated 4-May-13 6:56am
v5
Comments
Ian A Davidson 4-May-13 4:28am    
Looks like you are missing a closing bracket.

1 solution

Have you tried:
SQL
SELECT [R-Date] FROM  Reg WHERE (CONVERT(INT,REPLACE(Reg.[R-Date], '/', '') )) BETWEEN 13920201 AND 13920222

But that value looks more date-ish than integer. What are you trying to do here? Wouldn't date datatypes be a better idea altogether?
 
Share this answer
 
Comments
Member 10010932 4-May-13 4:54am    
Thanks man it really worked

What I'm trying to do here is:
due to that date/time format isn't suitable for Persian date;
i had to save my date as string!
and also i wanted to display dates in my report and i couldn't convert all of my records every time i SELECT them

the only problem was in selecting between 2 dates and you solved it for me

Thanks again
OriginalGriff 4-May-13 5:42am    
Have you seen this: http://persiandate.codeplex.com/

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900