question

kandanDevi avatar image
kandanDevi asked

How do I update a count?

Below is my scenario... I have table with columns like SLNO, Email, Date, NTES (No of time email send) SLNO = Serial Number Email = List of emails Date = Email sent date NTES = Count (No of times emails exist) The NTES column has to be updated by running a query (please help me with the query) and one more new column has to be inserted and it has to updated by the query Column Name = LESD. Matrix for this column is: If NTES is one, then the corresponding information from date column has to be updated in this column. If the NTES is >1 then the date information has to be considered from recently inserted date... The yellow coloured cells are the expected output. Can you give me any suggestions about an appropriate SQL query? Thanks, Kandan.M ![alt text][1] [1]: /storage/temp/2723-kandansql.png
sql-server-2012date-and-time-functions
kandansql.png (9.4 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KenJ avatar image KenJ commented ·
Are you familiar with the UPDATE statement? Here is a generalized pseudo-query to update the NTES column: UPDATE your_table_name SET NTES = some_value WHERE some_expression_is_true More info - http://www.w3schools.com/SQl/sql_update.asp If you can post what you have tried so far, that would be helpful.
0 Likes 0 ·

1 Answer

·
erlokeshsharma08 avatar image
erlokeshsharma08 answered
select slno, email,DATE,ntes, case when ntes=1 then DATE when ntes > 1 then (select MAX(date) from your_table) else '' end as LESD from your_table
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.