Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Retrieving value from EXEC(@sql)
  2. SELECT top (value) field, field2 FROM table
  3.        
  4. SELECT @first = min(field2) FROM (SELECT top (value) field, field2 FROM table)
  5.        
  6. DECLARE @RowCount int -- =25 -- sql server 2008 allows to assign when declaring
  7. SELECT @RowCount = 25
  8.  
  9. SELECT TOP (@RowCount) * FROM table1
  10.        
  11. DECLARE @RowCount int
  12. SELECT @RowCount = 25
  13.  
  14. SET ROWCOUNT @RowCount
  15. SELECT  * FROM table1
  16.  
  17. SET ROWCOUNT 0  -- make sure to set back to 0 otherwise
  18.                 -- queries below will return 25 rows
  19.        
  20. declare @top int = 10
  21.  
  22. select top (@top) field, field2 from table