我正在使用此代码:
WITH cte AS(SELECT panelname FROM inventorypanelcaptions UNION ALL SELECT CAST(0 AS VARCHAR(50)) FROM INVENTORYPANELCAPTIONS) SELECT CASE WHEN cast(min(right(panelname, 2) + 1) as varchar(50)) < 10 THEN 'o0' ELSE 'o' END + cast(min(right(panelname, 2) + 1) as varchar(50)) FROM cte WHERE NOT EXISTS ( SELECT panelname FROM inventorypanelcaptions WHERE right(inventorypanelcaptions.panelname, 2)= right(cte.panelname, 2)+1) ", con);
我在'With'
附近的语法不正确答案 0 :(得分:1)
要使它在SQL 2000中工作,您可以将其移动到子查询
SELECT CASE WHEN cast(min(right(panelname, 2) + 1) as varchar(50)) < 10 THEN 'o0' ELSE 'o' END + cast(min(right(panelname, 2) + 1) as varchar(50))
FROM (
SELECT panelname FROM inventorypanelcaptions UNION ALL SELECT CAST(0 AS VARCHAR(50))
FROM INVENTORYPANELCAPTIONS
) cte
WHERE NOT EXISTS ( SELECT panelname
FROM inventorypanelcaptions
WHERE right(inventorypanelcaptions.panelname, 2)= right(cte.panelname, 2)+1
) ", con);