Posts

Showing posts from January, 2021

How to Transform String in SQL Server

Image
How to Transform String in SQL Server Say for example if you have column which is returning values such as 401*1 and you want to extract number from string T-SQL Code:  Select '401*1' AS ALTERNATE_ID, REVERSE(PARSENAME(REPLACE(REVERSE('401*1'), '*', '.'), 1)) As TransformedAlternateID

How to execute a job step based on outcome of previous SQL Agent job step?

There was a requirement to stop a SQL Server Agent job if any of the Staging Tables are not loaded in to Data warehouse And to keep it simple and perform this action - I have added a step in SQL Server Agent Job to check Audit table to ensure all the Staging tables are loaded before loading them in to Data warehouse   DECLARE @dbState INT; SELECT @dbState = RowCountCheck FROM [StagingDatabase].[vwEtlRowCountCheck]  WHERE RowCountCheck = 0 --AND TableName NOT IN ('Audit_Log', 'Config','CHARGES_DUE_PER_ASSET') ; IF @dbState = 0 BEGIN   RAISERROR('All Staging tables are not loaded correctly', 11, 1); END