Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

CSS
1   Manish  2012-09-24 16:46:12.037 1
3   nilam   2012-09-24 16:59:23.173 1
2   Dev     2012-09-24 17:04:22.907 1
1   Manish  2012-09-24 17:07:44.967 1
3   nilam   2012-09-24 17:09:38.950 1


i m having the above table..as u can see the same name has 2 entries..the last colum is for attendence.so i want to add those values.
e.g. for each person it sould keep on add each time
Posted

Hi,

See the following solution. It might be help you.

SQL
IF (Select Count(ID) From Table_4 Where Name = 'Viprat') = 0
BEGIN
    Insert Into Table_4 (Name, Attendance)
    Values ('Viprat',1)
END
ELSE
BEGIN
    Update Table_4
    SET
        Attendance = Attendance + 1
    Where Name = 'Viprat'
END


You can insert like this.

Thanks,
Viprat
 
Share this answer
 
Comments
[no name] 25-Sep-12 1:57am    
Hi VIPR@T
Thanks for ur solution but i am not looking for this..
what i am looking is as u can see in my table there are 3 names..so i want is only the last column should change..number of rows should be 3 only
e.g.
1 Manish 2012-09-24 16:46:12.037 1+1+1+1+1 and so on....
3 nilam 2012-09-24 16:59:23.173 1+1+1+1+1 and so on....
2 Dev 2012-09-24 17:04:22.907 1+1+1+1+1 and so on....
it should add like 1 then 2 then 3 and so on..
VIPR@T 25-Sep-12 2:02am    
hi,
see the solution, if you insert data like this query then you will get the same output as you want. just try once after executing querty.
[no name] 25-Sep-12 2:09am    
Hi
one more thing is how to pass the values..means u types ur name there but how to pass random values there..
VIPR@T 25-Sep-12 2:13am    
you can pass parameter in your stored procedure..
have you no idea how to pass the values through the parameter then see the below link.
http://www.devguru.com/technologies/t-sql/7132.asp
http://www.wiseowl.co.uk/blog/s263/parameters.htm
so here you can pass you name as a parameter
VIPR@T 25-Sep-12 2:38am    
Are you getting now??
Try this
SQL
SELECT NAME,COUNT(NAME) FROM TABLE_NAME 
GROUP BY NAME;

better to use primary key in the count and group by statement.

Like this
SQL
SELECT USER_ID,NAME,COUNT(PK_ID_OF_SEARCHING_TABLE) FROM TABLE_NAME 
GROUP BY USER_ID;
 
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