Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
districtid

2901
2906
2907


output

01
06
07


datatype is int

i tryed

select(substring(districtid,3,4) from tablename

but i am getting datatype error

can any one can suggest me.
Posted
Updated 3-Jan-13 19:20pm
v2
Comments
Sandeep Mewara 4-Jan-13 0:28am    
What datatype is 'districtid' in database?

Further, what error you get?

This way...
SQL
select right(convert(varchar,districtid) ,2) 
FROM tablename

Happy Coding!
:)
 
Share this answer
 
Comments
__TR__ 4-Jan-13 1:26am    
+5
Aarti Meswania 4-Jan-13 1:30am    
Thank you!
:)
Try,

SQL
SELECT districtid % 100 AS id
    FROM tablename
 
Share this answer
 
Comments
Sandeep Mewara 4-Jan-13 0:29am    
This would depend on the datatype of the column.
Salt Pepper 4-Jan-13 1:14am    
ya i tryed ur query SELECT districtid % 100 AS id
FROM tablename this i getting output
1
6
7
but i need output
01
05
06

that dist id is int datatype
Try
SQL
SELECT SUBSTRING(CAST(districtid AS VARCHAR),3,4) AS Output FROM TableName
 
Share this answer
 

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