Posts

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

Index on view

Let's say if we create index on a view  and if we alter the view then the index gets dropped and again we have to create a index on the view

knowing the server exist or not

Run the command in the command prompt : ping servername -t to know the details

Adding the primary key for two columns

CREATE   TABLE  Persons (     ID int  NOT   NULL ,     LastName varchar( 255 )  NOT   NULL ,     FirstName varchar( 255 ),     Age int, CONSTRAINT  PK_Person  PRIMARY   KEY  (ID,LastName)

Bidirectional Trigger ( Insert in one table and reflected in another table and vice versa)

Concept : Enabling the trigger on first table and enabling the CT on other table to get the table data inserted. /* On first table */     CREATE TRIGGER [dbo].[InsertReportedsoftwareimages]    ON [dbo].[ReportedSoftwareImages]    AFTER INSERT    AS    IF @@ROWCOUNT > 0    BEGIN TRY;    SET NOCOUNT ON ;        -- dbo.SoftwareBuildRecords --------------    MERGE dbo.SoftwareBuildRecords AS tgt    USING (SELECT t.[Changerequestid],t.[softwareimageBuild],t.[softwareimagename], t.IsFoundOnSoftwareImage    FROM INSERTED t inner join    dbo.ChangeRequests_ProblemReport problemReports    ON t.ChangeRequestId = problemReports.Id and t.IsFoundOnSoftwareImage=1) as src    ON ( tgt.[Changerequestid] = src.[Changerequestid]    and tgt.softwareimagename = src.softwareimagename     )    WHEN NO...