declare @query varchar(8000) set @query = ''
I want to pass the below query to a variable (@query), here @dbid and @dbname are other variables.
"select @dbname,object_NAME(DM.[object_id],@dbid), SI.[name], index_type_desc, avg_fragmentation_in_percent from sys.dm_db_index_physical_stats (@dbname,null,null,null,null) as [DM] inner join sys.indexes [SI] on DM.object_id = SI.object_ID and DM.index_id = SI.index_id where --DM.avg_fragmentation_in_percent > 30 DM.avg_fragmentation_in_percent between 15 and 30 and index_type_desc <> 'HEAP' and SI.object_id NOT IN (SELECT ID FROM SYSOBJECTS WHERE XTYPE = 'U' AND CONVERT(VARCHAR,CRDATE,101) = '04/30/2009')"
How should i pass the above statement to @query variable.