Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL
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 8-Apr-13 20:46pm
Comments
Karthik Harve at 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 ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Maciej Los at 9-Apr-13 2:12am
   
+5!
Mehdi Gholam at 9-Apr-13 2:12am
   
Thanks Maciej!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

As Mehdi Gholam wrote, bad design of table, but still you can find solution (hard coded).
 
See example:
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
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