Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Batch Update depend on fromdate & group by

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2014-04-21 : 20:16:27
Hi All,

I have a table

eg:
ID Datt Amount
210 01/2012 400
210 02/2012 500
250 03/2012 600
280 04/2012 800
290 05/2013 1200
320 01/2013 200
:
:
982 02/2015 652

if my SP date input as 01/Apr/2012. Mean i want the rest of the value turn to be 0
eg:
ID Datt Amount
210 01/2012 0
210 02/2012 0
250 03/2012 0
280 04/2012 800
290 05/2013 0
320 01/2013 200
:
:
982 02/2015 652

Please advise.

Thank you.

Regards,
Micheale

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2014-04-22 : 06:37:56
select ID, Datt ,
Amount = case when Datt >= @d then Amount else 0 end
from tbl

if Datt is really mm/yyyy then use
convert(datetime,'01/'+Datt,103) in place of Datt in the case statement.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -