Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a varchar field in my table name as attendance

Its value as 25/25;

I need to get its answer as 1 while executing this value...
How it is possible???
Posted
Comments
Karthik Harve 9-Apr-13 1:56am    
your question is not clear. improve your question and tell us, what exactly, you are trying to do ? and where you stuck ?

You are better off breaking up the values in your database into separate columns so you can compute easily in Sql Server, or you can compute in c# code.
 
Share this answer
 
Comments
Maciej Los 9-Apr-13 2:12am    
+5!
Mehdi Gholam 9-Apr-13 2:12am    
Thanks Maciej!
As Mehdi Gholam wrote, bad design of table, but still you can find solution (hard coded).

See example:
SQL
DECLARE @val VARCHAR(30)
DECLARE @search VARCHAR(5)

SET @val = '25/25'
SET @search = '/'

SELECT MyFirstVal, MySecondVal, CONVERT(FLOAT, MyFirstVal/MySecondVal) AS Result
FROM (
    SELECT  CONVERT(INT, LEFT(@val, CHARINDEX(@search, @val)-1)) AS MyFirstVal,
            CONVERT(INT, RIGHT(@val, LEN(@val)- CHARINDEX(@search, @val))) AS MySecondVal
)AS T
 
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