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.
| Author |
Topic |
|
mj
Starting Member
25 Posts |
Posted - 2003-10-01 : 09:26:39
|
| Here is my scenario: Have records in a table, want to send email, using xp_sendmail, have to pull the lowest recordnumber from the table and set that equal to @emid, then loop through, and send the records. I'm getting a syntax error using keyword TOP, here is the query. I appreciate all assistance in advance, thanks mj.declare @EMid intselect @emid = top 1 SampleRequestID from dbo.vSampleRequest order by SampleRequestID asc --print @emidWhile (Select email From Dbo.vSampleRequest Where (SampleRequestID = @EmID)) is not nullbegin SELECT * from Dbo.vSampleRequest Where SampleRequestID = @emid EXEC master..xp_sendmail @recipients ='jordan_murphy@core.com',@message = 'test of Sp', @Subject = 'Sample Request Email'--print @emidset@emid = @emid + 1endGO |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-10-01 : 10:29:54
|
Pronoun trouble...Try this..USE NorthwindGO DECLARE @EMid int SELECT TOP 1 @EMid = OrderId FROM Orders ORDER BY OrderId SELECT TOP 1 OrderId FROM Orders ORDER BY OrderIdSELECT @EMid Brett8-)SELECT @@POST FROM Brain ORDER BY NewId()That's correct! It's an AlphaNumeric! |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2003-10-01 : 10:37:42
|
| I think, this will be faster.USE NorthwindGO DECLARE @EMid int SELECT @EMid = min(Orderid) FROM Orders HTH-------------------------What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-10-01 : 10:46:32
|
| Did I mention (today?) that I hate TOP...Anyway...the execution plan adds an extra step to the MIN code...Doing stream aggregates...The Traces are identical...but it's not a lot of data...Brett8-)SELECT @@POST FROM Brain ORDER BY NewId()That's correct! It's an AlphaNumeric! |
 |
|
|
|
|
|