Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update a date part
Message
 
 
À
17/10/2005 15:47:08
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01059700
Message ID:
01059786
Vues:
12
This message has been marked as a message which has helped to the initial question of the thread.
SET NOCOUNT ON

DECLARE @newdate DATETIME
DECLARE @tbl TABLE ( pk int IDENTITY, dt datetime, dtp datetime)

INSERT INTO @tbl (dt) VALUES ('1/1/1900 9:10:48')
INSERT INTO @tbl (dt) VALUES ('12/21/1998 14:45:48.123')
INSERT INTO @tbl (dt) VALUES (getdate())

SET @newdate = '2005-07-13'

UPDATE @tbl 
  SET dtp = dt, 
      dt = DATEADD(dd, DATEDIFF(dd, dt, @newdate), dt)

SELECT * FROM @tbl
>DATEPART selects the part of the date to extract, as does Day, Month, and Year. Is there a way to update a datetime field so that the original is not changed except for the part that needs to be? For example, if @settime = 1/1/1900 9:10:48 AM and I wanted to update it to 7/13/2005 9:10:48 AM, is there a set-based command that would do that?
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform