Archive for January, 2011

UPDATE – FROM … a simple solution

January 25, 2011

In order to avoid that side effect, a simple solution might be this,
create a temporary table, and use data via that table.

Here is a very simple example:

CREATE TABLE #tmp_date(datetime mydate,int idagent);

INSERT INTO #tmp_date (mydate, idagent)
SELECT GETDATE() as MyDate, ID
FROM Agents;

UPDATE Campaigns
SET Campaigns.FieldDate = A1.MyDate
FROM Campaigns AS C1 JOIN 
  #tmp_date AS A1
  ON C.IDAgent = A1.ID;

DROP TABLE #tmp_date;

UPDATE – FROM … again

January 23, 2011

I already told about UPDATE statement with FROM clause, here.
Have you already used with real-time generated data in SET clause ?
Something with GETDATE() o NEWID() … like this:

UPDATE Campaigns
SET Campaigns.FieldDate = A.MyDate
FROM Campaigns AS C JOIN 
  ( SELECT GETDATE() as MyDate, ID
    FROM Agents
  ) AS A
  ON C.IDAgent = A.ID;

What happened? 😦

You suppose GETDATE() returns a value same as A2.ID, a unique date paired to agent ID, and that value will not change… WRONG!
It’s a function, and that value will change every time SET clause run. 😦

Please, try with NEWID() and you’ll see. :/
I’ll have a look deeper, something does’nt work as expected.

Technorati tags: SQL Server, SQL, UPDATE

Clickonce: which version is running ?

January 22, 2011
public Version ThisVersion
{
  get
  {
        if (ApplicationDeployment.IsNetworkDeployed)
          retunn ApplicationDeployment.CurrentDeployment.CurrentVersion;

        return Assembly.GetEntryAssembly().GetName().Version;
  }
}

When running in debug mode, this code return build number, i.e. 1.0.45032.12376,
but in deploy enveironment it return a valid code: 1.4.2.232 πŸ˜‰

source: Howto: Programmatically get the (Click-Once Published) Version of a .NET Application in C#

DBCC SHRINK log updated in SQL Server 2008 R2

January 16, 2011

The old snippet code I used to use until SQL Server 2005, in order to shrink log data file doesn’t work in SQL Server 2008 R2.
Some minor changes to constants and keywords, made that snipped obsolete.

Here is new syntax page for DBCC SHRINKFILE .

source: DBCC SHRINKFILE (Transact-SQL) by MSDN

Good bye Cell ;(

January 15, 2011

This news moved old memories to present.

Sony will stop Cell production in the near future. 😦

source: Β Sony strengthens CMOS in buying back Toshiba plant
Sony buying back Cell chip fabrication facilities from Toshiba, it’s official