Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Select top 5 open query

Author  Topic 

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-12-02 : 13:43:00
Hello, how do I just select the top 5 (instead all records by using *) from below open query sample?

Select * from openquery ([@Server], '
SELECT * FROM @Schema.customerid
')

Thanks guys

SQLBoy

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-02 : 13:44:57
Try:

Select * from openquery ([@Server], '
SELECT TOP 5 * FROM @Schema.customerid
')

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-12-02 : 13:45:47
that does not work in open query. in normal swl query will work but not in open query. thanks tkizer.

SQLBoy
Go to Top of Page

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-12-02 : 13:57:01
actually, I figured it out...it is:
Select top 5* from openquery ([@Server], '
SELECT * FROM @Schema.customerid
')

SQLBoy
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-02 : 14:05:46
That was going to be my next suggestion. I think that's going to pull back the entire result set and THEN give you TOP 5. I would test to see if that's the case as it could be a performance issue, depending upon the amount of data there is in customerid.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -