我正在尝试获取一组zipcodes的MODE平均值(包含特定上传设置中大多数条目的邮政编码)。我想使它成为标量函数,而不是存储过程。
为什么这样做:
Select Top 1 LocationZip
from UploadSetZipCodeCount
where WorkOrderSet = 31
Order by ZipCount desc
但不是这样:
Select @setbasezip= Top 1 LocationZip
from UploadSetZipCodeCount
where WorkOrderSet = 31
Order by ZipCount desc
我的声明类型对于LocationZip字段是正确的。
答案 0 :(得分:5)
语法问题...... select top 1
应该在变量赋值之前出现:
Select Top 1 @setbasezip = LocationZip
from UploadSetZipCodeCount
where WorkOrderSet = 31
Order by ZipCount desc