Posts

Showing posts from February, 2020

Count and Unique identifier value

---------------  Count in the table --------------- select count(1) from table sp_spaceused '[audit].ChangeRequestSecurityVulnerabilityHistory' ----------------- Inserting the data in the column of unique identifier ---------- [Guid] [uniqueidentifier] NOT NULL --- insert the data in Unique identifier NEWID ( )

Executing the function with the table type and parameter

use prism DECLARE @Variable AS audit.ChangeRequestActivityQueueType  INSERT INTO @Variable([ChangeRequestId],[Guid],[Timestamp],[ChangeRequestHistoryTransactionId],[CommentHistoryId])  VALUES(12345,NEWID ( ),'2-21-2020',12345,12345)  SELECT * from  [audit].[GetChangeRequestSecurityUpdateActivities](@StudentVariable)  

T-SQL Script to find High CPU Queries

SELECT TOP 50 Convert(varchar, qs.creation_time, 109) as Plan_Compiled_On, qs.execution_count as ' Total Executions ', qs.total_worker_time as ' Overall CPU Time Since Compiled ', Convert(Varchar, qs.last_execution_time, 109) as ' Last Execution Date / Time ', cast(qs.last_worker_time as varchar) +'    ( '+ cast(qs.max_worker_time as Varchar)+' Highest ever ) ' as ' CPU Time for Last Execution ( Milliseconds ) ', Convert(varchar,(qs.last_worker_time/(1000))/(60*60)) + ' Hrs ( i . e . ' + convert(varchar,(qs.last_worker_time/(1000))/60) + ' Mins & ' + convert(varchar,(qs.last_worker_time/(1000))%60) + ' Seconds ) ' as ' Last Execution Duration ', qs.last_rows as ' Rows returned ', qs.total_logical_reads/128 as ' Overall Logical Reads ( MB ) ', qs.max_logical_reads/128 ' Highest Logical Reads ( MB ) ', qs.last_logical_reads/128 ' Logi...

sql-server-full-text-search-contains-function

select top 2 * from dbo.OrbitSearchCacheLongTexts where fieldid=22  SELECT * FROM dbo.OrbitSearchCacheLongTexts WHERE CONTAINS(IndexedWords,'"*12345*"') and fieldid=22 SELECT * FROM dbo.OrbitSearchCacheLongTexts where IndexedWords like '%12345%' and fieldid=22

Removing special characters of a string using function

alter Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000))  Returns VarChar(1000)  AS  Begin        Declare @KeepValues as varchar(50)      Set @KeepValues = '%[^0-9a-zA-Z @\.\-]%'      While PatIndex(@KeepValues, @Temp) > 0          Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')        Return @Temp  End ================================================================= use ods ;with CR AS( select issue_id,  stringvalue from ssistemp.jirastage.JiraDroidBugIssueCustomfieldvalue  where custom_field_id = 10686 ) select CC=dbo.RemoveNonAlphaCharacters(CASE WHEN (CR.Stringvalue LIKE 'http://prism.qualcomm.com/CR/%'                   or CR.Stringvalue  LIKE 'https://orbit/CR/%' ) then replace(replace(CR.Stringvalue,'http://prism.qualcomm.com/CR/',''),'https://...

Audit enable on a table for select , delete ,insert

https://bradmcgehee.com/2010/03/30/an-introduction-to-sql-server-2008-audit/ db_owner -> nly owner can see the data in the audit file. public -> it gets inserted in the audit file To read from the Audit file SELECT top 10 * FROM sys.fn_get_audit_file ('E:\DBA\PrismAuditForPTR_9D053EB5-1A04-473C-A5DB-7F5A6779B8F6_0_132258070574800000.sqlaudit',default,default);    SELECT  top 50 statement FROM sys.fn_get_audit_file ('E:\DBA\PrismAuditForPTR_9D053EB5-1A04-473C-A5DB-7F5A6779B8F6_0_132258070574800000.sqlaudit', default,default) where database_principal_name<>'NA\crmdbsvc'

Splitting the column delimited by comma in ssis using script task

http://bi-polar23.blogspot.com/2008/06/splitting-delimited-column-in-ssis.html