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)
Condition in union all
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 28, 2013, 6:13 PM EST
try following script
declare @maxcount int=15
Select top(@maxcount) * from (
SELECT * FROM PG_table1 WITH (NOLOCK)
WHERE ISNULL(BatchId,0) != 0 AND [Status] = 7
and WebsiteId in (136)
union all
SELECT * FROM PG_table1 WITH (NOLOCK)
WHERE ISNULL(BatchId,0) != 0 AND [Status] =7
and WebsiteId in (138)
) A order by A.WebsiteId
Instead of this you can also use @@RowCount to get result
hope this will help you.