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)
Loading
Jignesh TrivediPosted Jan 28, 2013, 11:13 PM
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.