I have a table named Field that looks like this:
names | Table --------------- + ---------------- DATAFound | Table 1 update date | Table 2 Date Charges | Table 3 Date Lists | Table 4 Date Table 5 And what I want to do is change all the fields of the year to their specified table in 2013. If all these related tables have all the datetime fields, then basically, I have to convert the date to Table 1, 06/12/2009 16:14:23 to 06/12/2013 16:14:23.
Is it easy to do something like saying:
from SELECT (SELECT [Name] field) (Selection [Table])
with cursor and dynamic sql, something like that.
DECLARE @changeYear datetime SET @changeYear = 2013-01- 01 'DECLARE @tableName varchar (50), @columnName varchar (50) updateTime_Cursor declare name for cursor, field from field OPEN updateTime_Cursor FETCH next updateTime_Cursor INTO @columnName, @tableName WHILE @@ FETCH_STATUS = 0 start DECLARE @sql nvarchar (1000) SELECT @sql = 'update dbo.'+@tablename+' set '+ @ columnName +' = DATEADD (yy, DATEDIFF (yy, '+ @ columnName +', @change year), '+ @ columnName +') 'EXEC sp_executesql @ sql, n' change you periodically ', change year and close Update datecmer DEALLOCATE updateTime_Cursor
No comments:
Post a Comment