﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / What would be right approach? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 22:46:31 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: What would be right approach?</title><link>http://www.sqlservercentral.com/Forums/Topic1353315-392-1.aspx</link><description>[quote][b]Shadab Shah (9/2/2012)[/b][hr]I have a table which contains data for 12 months. Now i want to delete the data for the month of Aug, and insert new data which is present with me. For which i would do the following[code="sql"]delete from MyTable where Cdate between ('2012-08-01','2012-08-31')[/code]Now my question is How to insert  the new data into database. Is it like writing 31 insert statement?[/quote]I'm pretty sure the answer is "NO" but have to make sure... do any of those dates have times other than midnight on them?  Also, what is the data-type of the Cdate column?</description><pubDate>Fri, 07 Sep 2012 19:46:12 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: What would be right approach?</title><link>http://www.sqlservercentral.com/Forums/Topic1353315-392-1.aspx</link><description>[quote] But that means i have to write update 31 times. Can't this be eliminated by some means[/quote]You put you put the new data in a table, then invoke that table in the USING clause of a MERGE statement. A better question is why you have a table limited to 12 months instead of a  correctly declared table of what ever entities it models, with a temporal attribute.</description><pubDate>Tue, 04 Sep 2012 22:16:14 GMT</pubDate><dc:creator>CELKO</dc:creator></item><item><title>RE: What would be right approach?</title><link>http://www.sqlservercentral.com/Forums/Topic1353315-392-1.aspx</link><description>May be that:[code="sql"]SELECT	DATEADD (DAY,sv.Number,'20120801')FROM	master.dbo.spt_values svWHERE	sv.Name IS NULL AND sv.Number &amp;lt; 31[/code]</description><pubDate>Sun, 02 Sep 2012 22:28:46 GMT</pubDate><dc:creator>dab1037</dc:creator></item><item><title>RE: What would be right approach?</title><link>http://www.sqlservercentral.com/Forums/Topic1353315-392-1.aspx</link><description>[quote][b]Shadab Shah (9/2/2012)[/b][hr][quote][b]dwain.c (9/2/2012)[/b][hr]Why don't you just use UPDATE (if all 31 rows are present) or MERGE (if they are not)?[/quote]But that means i have to write update 31 times. Can't this be eliminated by some means[/quote]No it does not.  You'd need to do something like this:[code="sql"];WITH MyNewData (a,b,c) AS (    SELECT 1, 2, 3    UNION ALL SELECT 2, 3, 4    -- etc. for 28 more records    UNION ALL SELECT 31, 4, 5)UPDATE tSET b=d.b     -- new data for column b    ,c=d.c       -- new data for column cFROM MyTable tINNER JOIN MyNewData d    ON d.a = t.a[/code]My column "a" is your "CDate."</description><pubDate>Sun, 02 Sep 2012 22:27:29 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: What would be right approach?</title><link>http://www.sqlservercentral.com/Forums/Topic1353315-392-1.aspx</link><description>[quote][b]dwain.c (9/2/2012)[/b][hr]Why don't you just use UPDATE (if all 31 rows are present) or MERGE (if they are not)?[/quote]But that means i have to write update 31 times. Can't this be eliminated by some means</description><pubDate>Sun, 02 Sep 2012 22:18:21 GMT</pubDate><dc:creator>Shadab Shah</dc:creator></item><item><title>RE: What would be right approach?</title><link>http://www.sqlservercentral.com/Forums/Topic1353315-392-1.aspx</link><description>Why don't you just use UPDATE (if all 31 rows are present) or MERGE (if they are not)?</description><pubDate>Sun, 02 Sep 2012 21:29:06 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>What would be right approach?</title><link>http://www.sqlservercentral.com/Forums/Topic1353315-392-1.aspx</link><description>I have a table which contains data for 12 months. Now i want to delete the data for the month of Aug, and insert new data which is present with me. For which i would do the following[code="sql"]delete from MyTable where Cdate between ('2012-08-01','2012-08-31')[/code]Now my question is How to insert  the new data into database. Is it like writing 31 insert statement?</description><pubDate>Sun, 02 Sep 2012 21:21:44 GMT</pubDate><dc:creator>Shadab Shah</dc:creator></item></channel></rss>