Click here to Skip to main content
11,926,933 members (54,569 online)
Rate this:
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
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 ?
Rate this: bad
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.
Maciej Los 9-Apr-13 2:12am
Mehdi Gholam 9-Apr-13 2:12am
Thanks Maciej!
Rate this: bad
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:
SET @val = '25/25'
SET @search = '/'
SELECT MyFirstVal, MySecondVal, CONVERT(FLOAT, MyFirstVal/MySecondVal) AS Result
    SELECT  CONVERT(INT, LEFT(@val, CHARINDEX(@search, @val)-1)) AS MyFirstVal,
            CONVERT(INT, RIGHT(@val, LEN(@val)- CHARINDEX(@search, @val))) AS MySecondVal

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.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