UPDATE – FROM … again

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
Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: