1

Stored Procedure:-

CREATE PROCEDURE [dbo].[RT_SelectAll_BatchHistory_By_SchedulerTime]
@Skip INT,
@Take INT,
@ResultCode AS INT = 0 OUTPUT,
@ResultText AS VARCHAR(50)=NULL OUTPUT
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY 
SELECT
       [SchedulerTime]
      ,[ExecutedOn]
      ,[FinishedOn]
FROM   [T_Scheduler] WITH(NOLOCK)
WHERE [IsActive] = 1 
ORDER BY [SchedulerID]
OFFSET @Skip ROWS
FETCH NEXT @Take ROWS ONLY
SET @ResultCode = 0
SET @ResultText='SUCCESS'
END TRY
BEGIN CATCH
SET @ResultCode = -1
SET @ResultText='ERROR'
END CATCH
END

In this Stored procedure want to select All rows from SchedulerTime column and Null values From executedOn and finishedOn.

how can achieve this condition?

3 Answers 3

1
SELECT
       [SchedulerTime]
      ,[ExecutedOn]
      ,[FinishedOn]
FROM   [T_Scheduler] WITH(NOLOCK)
WHERE [IsActive] = 1 AND [ExecutedOn] IS NULL AND [FinishedOn] IS NULL

This Worked Fine for me

Sign up to request clarification or add additional context in comments.

Comments

0

Considering you are aware of the dirty reads in your code, you can try something like this..

SELECT
       [SchedulerTime]
      ,[ExecutedOn] = NULL
      ,[FinishedOn] = NULL
FROM   [T_Scheduler] WITH(NOLOCK)
WHERE [IsActive] = 1 
ORDER BY [SchedulerID]

Comments

0

Use NULLIF in your SELECT Query

 SELECT
       [SchedulerTime]
      ,NULLIF([ExecutedOn],[ExecutedOn]) AS [ExecutedOn]
      ,NULLIF([FinishedOn],[FinishedOn]) AS [FinishedOn]
FROM   [T_Scheduler] WITH(NOLOCK)
WHERE [IsActive] = 1 
ORDER BY [SchedulerID]
-----------------------------------------------    
SELECT
       [SchedulerTime]
      ,NULL AS [ExecutedOn]
      ,NULL AS [FinishedOn]
FROM   [T_Scheduler] WITH(NOLOCK)
WHERE [IsActive] = 1 
ORDER BY [SchedulerID]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.