Click here to Skip to main content
11,577,710 members (64,314 online)
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 19: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 Peter Leow 180
1 DamithSL 170
2 Richard MacCutchan 125
3 OriginalGriff 115
4 Abhinav S 100
0 OriginalGriff 830
1 Sergey Alexandrovich Kryukov 701
2 Abhinav S 573
3 F-ES Sitecore 420
4 Dave Kreskowiak 374


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2015
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