SQL Server随机获取其中一条GRID数据
SELECT
WO.市,WO.名称,WO.区县,新区县=CASE WHEN WO.区县='X化州区' THEN '城区' ELSE WO.区县 END,
CASE WHEN WO.名称 ='信息为空' OR WO.名称 IS NULL THEN
(SELECT TOP 1 G.GRID FROM tjs_grid G
WHERE G.City = WO.市
AND (CASE WHEN WO.区县='X化州区' THEN '城区' ELSE WO.区县 END)
LIKE '%' + SUBSTRING(G.GRID,3,2) + '%' ORDER BY NEWID()
)
ELSE WO.名称 END AS GRID新网格
FROM install_form_view WO WHERE WO.市 IS NOT NULL AND WO.区县 IS NOT NULL