Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends,
I have a varchar field in my Database Table named 'Enquiry Id'.
Value entering into it As 'Enquiry Id:2234'.
how to wright query for getting 2234 seperately as an integer value?????????
Eg: Enquiry Id='Enquiry Id:2234'
Query Result=2234
Posted

SQL
select cast(substring([Enquiry id],12,len([Enquiry Id])) as int) from tablename


try this
this will be helpful if this string "Enquiry id:" in your column is fixed.
 
Share this answer
 
v3
see below
SQL
select REPLACE('Enquiry Id:2234','Enquiry Id:','')

you can cast also
SQL
select CAST(REPLACE('Enquiry Id:2234','Enquiry Id:','') as int)
 
Share this answer
 
v3

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