Sorry if this is a really simple question, but how do I select the top 1 into a variable? Something like this (but not this as it doesn't work!):
SELECT @ID = TOP 1 OrderVal FROM qryCust WHERE OrderNo = '000663' AND DiscountGroup = 'XXND' AND CustID = 3
I'd just lie to add that I am building this up as a sQL string as I have a variable mnumber and combination of parameters to include in the where clause.
So my@ID is the output parameter from my sp_executesql.