April 16, 2019 at 4:40 pm
I have the following t-sql 2012 and I would like to create a backup table by using the where clause. I
want the where clause since I want to limit the number of rows that are in the backup table.
Thus would you show me how to modify the sql listed below so that it will run correctly in sql server management studio?
declare @qry nvarchar(max);
set @qry='SELECT * into ContactLog_'
+ cast(year(getdate()) as varchar(4))
+ cast(month(getdate()) as varchar(2))
+ cast(day(getdate()) as varchar(2))
+ 'FROM ContactLog
+ 'where [module]=''StudentServices''
+ and [contactMode] = ''Parent/Guardian''
+ and [contactType] = 2
+ and text like ''%dd1.org%''
+ and text like ''%/letter.aspx%''
+ and datetimestamp >= ''2008-08-01 00:00:00.00''
exec (@qry)
April 16, 2019 at 5:22 pm
How about this?
DECLARE @qry NVARCHAR(max);
SET @qry = 'SELECT * into ContactLog_' + cast(year(getdate()) AS VARCHAR(4)) + cast(month(getdate()) AS VARCHAR(2)) + cast(day(getdate()) AS VARCHAR(2)) + ' FROM ContactLog' + ' where [module]=''StudentServices''' + ' AND [contactMode] = ''Parent / Guardian''
AND [contactType] = 2
AND TEXT LIKE ''%dd1.org%''
AND TEXT LIKE ''%/letter.aspx%''
AND datetimestamp >= ''2008-08-01 00:00:00.00'''
PRINT (@qry)
--Exec (@qry)
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply