Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL top 1 parameter assignment issue

I'm trying to get the MODE average for a set of zipcodes (zip code with most entries in a particular upload set). I want to make this a scalar function, instead of a stored procedure.

Why does this work:

Select Top 1 LocationZip
from UploadSetZipCodeCount
where WorkOrderSet = 31
Order by ZipCount desc

But not this:

Select @setbasezip= Top 1 LocationZip
from UploadSetZipCodeCount
where WorkOrderSet = 31
Order by ZipCount desc

My declaration type is correct for the LocationZip field.

like image 880
Leah Hurst Avatar asked Apr 09 '12 17:04

Leah Hurst


1 Answers

Just a syntax issue... select top 1 should come before the variable assignment:

Select Top 1 @setbasezip = LocationZip
from UploadSetZipCodeCount
where WorkOrderSet = 31
Order by ZipCount desc
like image 55
Michael Fredrickson Avatar answered Oct 18 '22 19:10

Michael Fredrickson