mohit ranjan

mohit ranjan

  • NA
  • 51
  • 0

condition in union all

Jan 28 2013 5:55 AM
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)