1
Answer

condition in union all

mohit ranjan

mohit ranjan

11y
1k
1
i have to extract 15 record i want my query like this 

declare @maxcount int=15

SELECT TOP (@maxcount ) *   FROM  PG_table1  WITH (NOLOCK) 
  WHERE ISNULL(BatchId,0) != 0 AND  [Status] = 7  
  and WebsiteId in (136)


(but if this query return 10 rows then below return 5 row)
  union  all
 
  SELECT TOP (@maxcount-no. of row extracted from above query) *  FROM  PG_table1 WITH (NOLOCK)
  WHERE ISNULL(BatchId,0) != 0 AND  [Status] =7
  and WebsiteId in (138) 
Answers (1)